VBScript FormatDateTime function
VBScript FormatDateTime
VBScript FormatDateTime() function is used to format specified date. It returns a valid date and time expression.
Syntax
FormatDateTime(date,format)
Parameter Description
Parameter | Required? | Explanation |
---|---|---|
date | Required | It is string expression representing date |
format | Optional | Format can be any valid value specified in below table. |
Valid Format Value
Numeric Value | String Representation | Return Value |
---|---|---|
0 | vbGeneralDate | Default |
1 | vbLongDate | Returns date |
2 | vbShortDate | Returns date |
3 | vbLongTime | Returns time |
4 | vbShortTime | Returns time |
Example :
<!DOCTYPE html> <html> <body> <script language="vbscript" type="text/vbscript"> d1 = "2025-01-11 10:11" document.write("Example 1 : " & FormatDateTime(d1) & "<br />") document.write("Example 2 : " & FormatDateTime(d1,1) & "<br />") document.write("Example 3 : " & FormatDateTime(d1,2) & "<br />") document.write("Example 4 : " & FormatDateTime(d1,3) & "<br />") document.write("Example 5 : " & FormatDateTime(d1,4) & "<br />") </script> </body> </html>
Output :
After running above script in IE we will get following output -
Example 1 : 1/11/2024 10:11:00 AM Example 2 : Tuesday, January 11, 2025 Example 3 : 1/11/2024 Example 4 : 10:11:00 AM Example 5 : 10:11