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

ParameterRequired?Explanation
dateRequiredIt is string expression representing date
formatOptionalFormat can be any valid value specified in below table.

Valid Format Value

Numeric ValueString RepresentationReturn Value
0vbGeneralDateDefault
1vbLongDateReturns date
2vbShortDateReturns date
3vbLongTimeReturns time
4vbShortTimeReturns 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