Microsoft KB Archive/222178

{|
 * width="100%"|

VBScript Date Function Returns Two-Digit Year for Dates Past 2000

 * }

-

The information in this article applies to:


 * Microsoft Internet Information Server versions 3.0, 4.0
 * Microsoft Internet Information Services version 5.0

-

SYMPTOMS
The Date function in Microsoft Visual Basic Script (VBS) always returns a two-digit year for dates past the year 2000.

CAUSE
This is by design.

Visual Basic Script (VBS) includes several functions for manipulating dates, and the Date function always returns a "short date." In the U.S., it is typically in mm/dd/yy format.

Although dates returned by this function only display a two-digit year, the date value used internally by VBS uses the full year value. Therefore, using a combination of functions such as Year(Date) will return the correct year.

WORKAROUND
The following Active Server Pages (ASP) code will display several possible date output formats using built-in VBS functions, as well as defining two user-defined functions named FormatYear and LongYear that will return a short date with a four-digit year, or in mm/dd/yyyy format.

To use this example, copy the ASP code and save it as "DateTest.asp" (without the quotation marks) in a directory or virtual directory with Script access enabled. When you browse the page, it will display a table with several code samples for manipulating dates.

<%@Language="VBSCRIPT"%> VBScript Date Examples <% Function FormatYear(tmpDate) FormatYear = Month(tmpDate) & "/" & Day(tmpDate) & "/" & Year(tmpDate) End Function

Function LongYear LongYear = Month(Date) & "/" & Day(Date) & "/" & Year(Date) End Function %>

VBScript Date Examples

Using built-in functions

Using user-defined functions

MORE INFORMATION
Information on Microsoft and Year 2000 issues can be found in the Microsoft Year 2000 Resource Center.

Information on Microsoft Scripting Technologies can be found on the Microsoft Scripting Technologies Web site.

Additional query words: Y2K VBS ASP

Keywords :

Version : winnt:3.0,4.0

Platform : winnt

Issue type :

Technology :