VBScript Date
To display the date using VBScript, you use the VBScript date() function.
| Code |
|---|
|
|
VBScript Date Code
To display this to the user, you need to output it like you would anything else - for example, using the document.write() method.
| Code |
|---|
|
|
Or even better, you could put the date into a variable first, then output the variable:
| Code |
|---|
|
|
Both these result in the following.
Note: If this is blank, your browser probably doesn't support VBScript. Try using Internet Explorer.
| Code | Result |
|---|---|
|
|
VBScript Date Format
You can use the VBScript FormatDateTime() method to format the date to either a long date format or a short date format.
The FormatDateTime() method accepts two arguments: The date being formatted, and the required format (indicated by a constant). The formats are specified as follows:
- 0 - This represents the default date format (as in the previous example)
- 1 - This represents the long date format (based on the user's regional settings)
- 2 - This represents the short date format (based on the user's regional settings)
Long Format
To use long date format, you pass the FormatDateTime() an argument of 1.
| Code | Result |
|---|---|
|
|
Short Format
To use long date format, you pass the FormatDateTime() an argument of 2.
| Code | Result |
|---|---|
|
|

