VBScript FormatDateTime Function
Complete VBScript Reference
The FormatDateTime function formats and returns a valid date or time expression.
Syntax
|
FormatDateTime(date,format)
|
| Parameter |
Description |
| date |
Required. Any valid date expression (like Date()
or Now()) |
| format |
Optional. A value that specifies the date/time format to use
Can take the following values:
- 0 = vbGeneralDate - Default. Returns date: mm/dd/yy and time if specified: hh:mm:ss PM/AM.
- 1 = vbLongDate - Returns date: weekday, monthname, year
- 2 = vbShortDate - Returns date: mm/dd/yy
- 3 = vbLongTime - Returns time: hh:mm:ss PM/AM
- 4 = vbShortTime - Return time: hh:mm
|
Example
Example
Display a date 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>
|
The output of the code above will be:
2/16/2010 1:45:00 PM
Tuesday, February 16, 2010
2/16/2010
1:45:00 PM
13:45 |
Try it yourself »
|
Complete VBScript Reference
Create a free Flash website with our simple, online web design editing platform. Stunning templates
and user-friendly tools make website building easy and fun.
Start Creating your free website now!

The Altova MissionKit is an integrated suite of tools ideal for:
- XML development
- Web & Web services development
- Data mapping & integration
- Rendering & publishing XML & database data
- XBRL validation, taxonomy editing, transformation & rendering
The MissionKit for XML Developers includes XMLSpy® - the industry-leading XML editor; MapForce® - a
graphical data mapping, conversion, and integration tool; StyleVision® - a visual XSLT stylesheet designer;
DiffDog® - an XML-aware diff/merge tool; and 2 additional tools.
Try all 6 products free for 30 days!
Download a fully-functional free trial
|
|
|
|