PRB: Unexpected Date Value Returned from Format FunctionID: Q113327
|
When using the Date, Time, or Format function to return information about a Date/Time variable, you may get results other than what you expected. For Example, the following prints January:
Print Format$(4, "MMMM") ' Print the Month represented by number 4
The value 4 when interpreted as a date is Jan 3, 1900. Dates are stored in Variants of VarType 7 (Date) as double-precision numbers. This number represents a date from January 1, 100 through December 31, 9999 -- where January 1, 1900 is 2. Negative numbers represent dates prior to December 30, 1899.
To get the string "April" to print when the only date information available is the Month 4, use a function such as DateSerial and supply it with an arbitrary Day and Year.
Sub Command1_Click ()
Dim AnyDay As Integer
Dim AnyYear As Integer
AnyDay = 1 ' Allowed values are: 1 to 31
AnyYear = 1994 ' Allowed values are: 100 to 9999
Print Format$(DateSerial(AnyYear, 4, AnyDay), "MMMM")
End Sub
This behavior is by design.
Additional query words: kbvbp300 kbDSupport FORMAT FORMAT$ DATESERIAL vb4sweep
Keywords : kbcode PrgOther
Version : WINDOWS:3.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: June 21, 1999