
- VBScript Tutorial
- VBScript - Home
- VBScript - Overview
- VBScript - Syntax
- VBScript - Enabling
- VBScript - Placement
- VBScript - Variables
- VBScript - Constants
- VBScript - Operators
- VBScript - Decisions
- VBScript - Loops
- VBScript - Events
- VBScript - Cookies
- VBScript - Numbers
- VBScript - Strings
- VBScript - Arrays
- VBScript - Date
- VBScript Advanced
- VBScript - Procedures
- VBScript - Dialog Boxes
- VBScript - Object Oriented
- VBScript - Reg Expressions
- VBScript - Error Handling
- VBScript - Misc Statements
- VBScript Useful Resources
- VBScript - Questions and Answers
- VBScript - Quick Guide
- VBScript - Useful Resources
- VBScript - Discussion
VBScript FormatDateTime Function
It is a function that helps the developers to format and return a valid date and time expression.
Syntax
FormatDateTime(date,format)
Parameter Description
date, a Required Parameter.
format, an Optional Parameter. The Value that specifies the date or time format to be used. It can take the following values −
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"> d = ("2013-08-15 20:25") document.write("Line 1 : " & FormatDateTime(d) & " <br />") document.write("Line 2 : " & FormatDateTime(d,1) & "<br />") document.write("Line 3 : " & FormatDateTime(d,2) & "<br />") document.write("Line 4 : " & FormatDateTime(d,3) & "<br />") document.write("Line 5 : " & FormatDateTime(d,4) & "<br />") </script> </body> </html>
When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −
Line 1 : 15/08/2013 8:25:00 PM Line 2 : Thursday, 15 August 2013 Line 3 : 15/08/2013 Line 4 : 8:25:00 PM Line 5 : 20:25
vbscript_date.htm
Advertisements