Microsoft KB Archive/96098

= FileDatetime Doesn't Include Time If File Time Is Midnight =

Article ID: 96098

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q96098



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(&quot;VB.EXE&quot;), &quot;mm/dd/yy hh:mm AMPM&quot;)



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
 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.  Add the following code to the Form_Click procedure for Form1: Sub Form_Click MsgBox FileDateTime(&quot;VB.EXE&quot;) End Sub 

A message box appears with the date 10/21/92, but the time stamp is not displayed.

Additional query words: 2.00 3.00

Keywords: KB96098

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.