Your source for ASP-related frequently asked questions and answers! : ASP FAQS : Dates and Times

Question: How can I easily display a nicely formatted date variable?

Answer: Use the FormatDateTime function. FormatDateTime takes two input paraemeters, a required date variable and an optional date format. There are five different date formats available:

vbGeneralDate - displays a date as a short date and a time as a long time.
vbLongDate - displays a date in the long format
vbShortDate - displays a date in the short format
vbLongTime - displays a time using the long format
vbShortTime - displays a time using the 24-hour format

The long and short formats are specified by the regional settings on the Web server. An example of using the FormatDateTime function can be seen below:

Dim dtNow
dtNow = Now()

Response.Write FormatDateTime(dtNow, vbGeneralDate) & "<BR>"
Response.Write FormatDateTime(dtNow, vbLongDate) & "<BR>"
Response.Write FormatDateTime(dtNow, vbShortDate) & "<BR>"
Response.Write FormatDateTime(dtNow, vbLongTime) & "<BR>"
Response.Write FormatDateTime(dtNow, vbShortTime) & "<BR>"

The output of the above script is:
9/24/00 3:23:48 PM
Sunday, September 24, 2000
3:23:48 PM

For more information be sure to read the technical docs! Also be sure to check out this FAQ: How can I display dates in a completely custom format (that might not be supported by FormatDateTime)?

FAQ posted by Scott Mitchell at 9/24/2000 3:44:53 PM to the Dates and Times category. This FAQ has been viewed 75,619 times.

Copyright 2019 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers