Library code snippets

Displaying a Date

Many people ask me how I get the day of the week and the full date to display on my web sites, well, it's easy.  Simply put the following three lines of code in your ASP page and presto!

var_date=date() 'get the current date
var_date=FormatDateTime(var_date,1)
Response.Write(var_date)

Formating options are:

VB Constant Name Value Description
vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed.
vbLongDate 1 Display a date using the long date format specified in your computer's regional settings.
vbShortDate 2 Display a date using the short date format specified in your computer's regional settings.
vbLongTime 3 Display a time using the time format specified in your computer's regional settings.
vbShortTime 4 Display a time using the 24-hour format (hh:mm).

Comments

  1. 14 Sep 2004 at 23:01

    Hello,


    How about this statement:


    vbShortTime - 4 - Display a time using the 24-hour format (hh:mm).


    If I want to Display a short time using the time format specified in your computer's regional settings?


    Thank You for suggestions :)


    Regardz,


    Sledge

  2. 13 Aug 2002 at 13:34

    You are glad you are not dealing with other languages and computer settings . This is not your nor mine mistake, but date formats are real madness sometimes. For example Windows API functions (used by VBScript in ASP) are able to generate correct Bulgarian date, but they are unable to parse it back! This happens even in MS Access, Excel etc. E.g. the problem is in the system provided formatting functions. Unfortunately this is not the only problem.


    For example this text 12.11.2000 can be parsed as 12 Nov 2000 and as 11 Dec 2000. Most formats using "." as date separator order the components day.month.year. However windows functions are trying to be "intelligent" and if you need an input from the user and your server is set to US localle you can expect many interesting situations. The "." will not cause error but sometimes you will receive a strange date value.


    Unending problem! Thus if you need input better set-up some kind of callendar - in a pop-up window, inline to generate the string and read the date manually in the ASP page.  

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Displaying a Date.

Leave a comment

Sign in or Join us (it's free).

Super Tal Always working hard!!
AddThis

Related discussion

Related podcasts

  • Scott Guthrie

    Scott catches up with Scott Guthrie in an interview covering Ajax, Asp 2.0, extender controls, CSS adapters and more.

Events coming up

Want to stay in touch with what's going on? Follow us on twitter!