FileDatetime Doesn't Include Time If File Time Is Midnight

Last reviewed: June 21, 1995
Article ID: Q96098
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic

  for Windows, versions 2.0 and 3.0

SUMMARY

Passing a file name with a time stamp of midnight to the function FileDateTime, returns a string containing only the date, not the time. This is consistent with the Format/Format$ function's General Date format, which when passed a DateTime string with a time of midnight returns a string containing only the date.

If your program needs to display a DateTime string with midnight represented by 12:00 AM or 00:00 (in 24-hour format), use the Format($) functions to perform the necessary conversion. By using Format$ or Format with the time format symbols h, m, and s, you can cause the Format($) functions to include a time format for midnight.

In the example below, a message box showing both the date and time of VB.EXE, which is midnight for version 2.0, is displayed with a time stamp.

   MsgBox Format$(FileDateTime("VB.EXE"), "mm/dd/yy hh:mm AMPM")

MORE INFORMATION

The internal structure of a serial number is a double precision number. The integral portion represents the number of days since December 30, 1899 and the fractional portion represents the time as a fraction of a day. Midnight is the beginning of a day and therefore it's represented by the fraction zero.

For example the serial number for 10/21/92 6:00 AM is represented by:

   33898.25

The date is 33898 days since 12/30/1899. The time is represented as one-fourth of the 24-hour day passed since midnight. One-fourth of 24 is exactly 6, so the time is 6 hours, 0 minutes, 0 seconds.

Using the General Date format for a DateTime string without using a time in Format($), automatically returns a formatted string without a time portion. This is by design. Because both midnight and DateTime strings without a time are represented internally as the same number, the General Date format processes the strings identically.

Steps to Reproduce Problem

  1. Run Visual Basic, or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

  2. Add the following code to the Form_Click procedure for Form1:

          Sub Form_Click
             MsgBox FileDateTime("VB.EXE")
          End Sub
    
    
A message box appears with the date 10/21/92, but the time stamp is not displayed.


Additional reference words: 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: PrgOther


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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.