Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AWS AI GO KOTLIN SASS VUE GEN AI CYBERSECURITY DATA SCIENCE
     ❯   

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/yyyy and time if specified: hh:mm:ss PM/AM.
  • 1 = vbLongDate - Returns date: weekday, monthname, year
  • 2 = vbShortDate - Returns date: mm/dd/yyyy
  • 3 = vbLongTime - Returns time: hh:mm:ss PM/AM
  • 4 = vbShortTime - Return time: hh:mm

Example

Example

Display a date in different formats:

<%

d=CDate("2019-05-31 13:45")
response.write(FormatDateTime(d) & "<br />")
response.write(FormatDateTime(d,1) & "<br />")
response.write(FormatDateTime(d,2) & "<br />")
response.write(FormatDateTime(d,3) & "<br />")
response.write(FormatDateTime(d,4) & "<br />")

%>

The output of the code above will be:

5/31/2019 1:45:00 PM
Friday, May 31, 2019
5/31/2019
1:45:00 PM
13:45
Show Example »

❮ Complete VBScript Reference
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2023 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.