Obtaining Date or Serial Result from DateSerial or DateValue

Last reviewed: March 20, 1998
Article ID: Q95510
2.00 3.00 WINDOWS kbprg

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SUMMARY

In Visual Basic version 2.0 and 3.0, the DateSerial and DateValue functions return a variant data type of VarType 7 (Date) instead of a date serial number. The date is still stored internally in the serial number format returned by the DateSerial and DateValue functions in Visual Basic version 1.0 and can be obtained by using the CDbl function in versions 2.0 and 3.0.

This is not a bug. This is a special feature of versions 2.0 and 3.0.

MORE INFORMATION

The return value for DateSerial and DateValue is a formatted date string in the format MM/DD/YY. If you pass it as an argument to the Print Method, Print # and Write # statements are printed as such. The line of code below prints the date as a formatted date string:

   Form1.Print DateSerial(1992,1,1)

To use the underlying serial number, use the Visual Basic CDbl statement to convert the variant return value to a double precision number. This can be useful for storing dates in a random access file because a double precision variable uses eight 8 bytes and a variant uses 16. The line of code below prints the date in serial number format:

   Form1.Print CDbl(DateSerial(1992,1,1))


Additional reference words: 2.00 3.00
KBCategory: kbprg
KBSubcategory: PrgOptTips


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.