PRB: VBScript Date and Time Formats Change with Logged on User

Article translations Article translations
Article ID: 218964 - View products that this article applies to.
This article was previously published under Q218964
Expand all | Collapse all

SYMPTOMS

When you use the VBScript Now, Date, or Time functions, the date and time formats differ depending on the user that is logged on to the computer. This creates a problem for server applications that are developed using Active Server Pages where the date or time formats are critical, but the date or time formats change when different users log on to the server or when no users are logged on.

For example, an application may require that you display the year in a four-digit format instead of a two-digit format (for example, 1999 versus 99). The user logs on to the Microsoft Internet Information Server (IIS) server and sets the Date format under Regional Settings in the Control Panel to use four-digit years (for example, mm/dd/yyyy). When the user opens the Active Server Pages (ASP) page in a browser, the year is displayed as four digits. When the user logs off the computer and opens the ASP page in a browser, the year is displayed as two digits.

CAUSE

The VBScript functions Now, Date, and Time rely on the Regional Settings in the computer for their formats. Regional Settings change, depending on the user who is logged on (or not logged on) to the computer. As a result, there is no way to guarantee that date and time formats will always be the same.

RESOLUTION

To ensure that your date and time formats are consistent, do one of the following:
  • Use JScript, which does not rely on the regional settings for its date and time formats.
  • Use functions other than Now, Date, and Time to display dates and times. Because the other date and time functions (for example, Day, Month, and Year) do not rely on regional settings, the formats do not change when different users log on to the computer. For example, the MyDate function always returns the date in mm/dd/yyyy format:
    Function MyDate()
         dteCurrent = Date()
    
         dteDay = Day(dteCurrent)
         dteMonth = Month(dteCurrent)
         dteYear = Year(dteCurrent)
    
         MyDate = dteMonth & "/" & dteDay & "/" & dteYear
       End Function
    					

REFERENCES

For more information on VBScript and JScript, visit the MSDN Scripting site at:
http://msdn2.microsoft.com/en-us/library/ms950396.aspx
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
248142 Default System Date Behavior in Windows NT 4.0 and Windows 2000

Properties

Article ID: 218964 - Last Review: August 8, 2007 - Revision: 2.1
APPLIES TO
  • Microsoft Active Server Pages 2.0
  • Microsoft Visual Basic, Scripting Edition 3.0
  • Microsoft Visual Basic, Scripting Edition 4.0
  • Microsoft Visual Basic, Scripting Edition 5.0
Keywords: 
kbprb kbscript KB218964
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com