Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML

Print Version

VBScript Date

To display the date using VBScript, you use the VBScript date() function.

date()

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.

document.write(date())

Or even better, you could put the date into a variable first, then output the variable:

localDate = date()
document.write(localDate)

Both these result in:

Note: If this is blank, your browser probably doesn't support VBScript. Try using Internet Explorer.

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.

localDate = FormatDateTime(date(), 1)
document.write(localDate)

This results in:

Short Format

To use long date format, you pass the FormatDateTime() an argument of 2.

localDate = FormatDateTime(date(), 2)
document.write(localDate)

This results in:

Enjoy this website?

  • Share
  • Add this page to your Favorites
  • Link to this page (copy/paste into your own website or blog):
  • Link to Quackit using one of these banner ads.
  • Help support Quackit by making a donation

Oh, and thank you for supporting Quackit!

© Copyright 2000 - 2010 Quackit.com