VBScript FormatDateTimeFunction
Complete VBScript Reference Manual
The FormatDateTime function formats and returns a valid date or time expression.
Syntax
FormatDateTime(date,format)
| Parameters | Description |
|---|---|
| date | Required. Any valid date expression (such as Date() or Now()). |
| format | Optional. The format value that specifies the date/time format to use. The following values can be used:
|
Examples
Examples
Display dates in different formats:
<script type="text/vbscript">
d=CDate("2010-02-16 13:45")
document.write(FormatDateTime(d) & "<br />")
document.write(FormatDateTime(d,1) & "<br />")
document.write(FormatDateTime(d,2) & "<br />")
document.write(FormatDateTime(d,3) & "<br />")
document.write(FormatDateTime(d,4) & "<br />")
</script>
d=CDate("2010-02-16 13:45")
document.write(FormatDateTime(d) & "<br />")
document.write(FormatDateTime(d,1) & "<br />")
document.write(FormatDateTime(d,2) & "<br />")
document.write(FormatDateTime(d,3) & "<br />")
document.write(FormatDateTime(d,4) & "<br />")
</script>
The output of the above examples is:
2/16/2010 1:45:00 PM
Tuesday, February 16, 2010
2/16/2010
1:45:00 PM
13:45
Tuesday, February 16, 2010
2/16/2010
1:45:00 PM
13:45
Try it Yourself »
Complete VBScript Reference Manual Other Extensions