Go to: Articles List
To format dates and times you simply need one function: FormatDateTime(). This function is detailed and
explained below:
FormatDateTime(Date[, Format])
- returns a date formatted as you specify
- the format parameter can have one of the following values:
0 - vbGeneralDate - Displays date as short date (if included), and time as long time.
1 - vbLongDate - Displays date as long date format
2 - vbShortDate - Displays date as short date
3 - vbLongTime - Displays time as long time
4 - vbShortTime - Displays time in 24 format (hh:mm)
Example:
var1 = Now()
Response.Write("var1 before formatting : " & var1 & "<br>")
Response.Write("var1 format 0 = " & FormatDateTime(var1,0) & "<br>")
Response.Write("var1 format 1 = " & FormatDateTime(var1,1) & "<br>")
Response.Write("var1 format 2 = " & FormatDateTime(var1,2) & "<br>")
Response.Write("var1 format 3 = " & FormatDateTime(var1,3) & "<br>")
Response.Write("var1 format 4 = " & FormatDateTime(var1,4) & "<br>")
Result:
var1 before formatting : 9/1/99 12:34:50 PM
var1 format 0 = 9/1/99 12:34:50 PM
var1 format 1 = Wednesday, September 01, 1999
var1 format 2 = 9/1/99
var1 format 3 = 12:34:50 PM
var1 format 4 = 12:34
|
|
|
|