Microsoft KB Archive/190315

= Last accessed time and last modified time reported by C Run-Time (CRT) functions can be adjusted by using the "Automatically Adjust for Daylight Saving Time" option =

Article ID: 190315

Article Last Modified on 1/23/2007

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q190315

<div class="symptoms_section">

SYMPTOMS
You can adjust the time of last access and time of last modification reported by the CRT functions _stat, _fstat, _findfirst, and _findnext for daylight saving time under the NTFS file system. This manifests itself as a change in the time last modified when making the switch to daylight savings time from standard time or vice-versa.

<div class="cause_section">

CAUSE
All of the previously referenced CRT functions call the Win32 API FileTimeToLocalFileTime. FileTimeToLocalFileTime adjusts the file times for daylight saving time if "Automatically adjust clock for daylight saving changes" is selected in the Date/Time Properties dialog box for the system clock. This behavior is by design under the NTFS file system.

<div class="resolution_section">

RESOLUTION
One way to avoid the behavior is to clear "Automatically adjust clock for daylight saving changes" in the Date/Time Properties dialog box for the system clock. Other workarounds depend upon the calculations or assumptions that are made based on the date/time last modified that is reported for a file.

Note If the time last modified is between 12:00 am and 1:00 am, the date last modified is also changed when the adjustment subtracts an hour from the time last modified in the Fall. Similarly, files with a time last modified between 11:00 pm and midnight will have their date last modified when the adjustment advances the time one hour in the Spring.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
This behavior is specific to the NTFS file system, and does not reproduce on a system using the FAT file system. Note that the CRT and the operating system report the same time last modified under all circumstances.

In the steps below, references to stat.exe mean the program generated by compiling stat.c, which appears below:

Sample code
/* STAT.C: This program uses the _stat function to   * report information about the file named STAT.C.    * Compile options: none. */

#include <time.h>  #include <sys/types.h>   #include <sys/stat.h>   #include <stdio.h>

int main(int ac, char **av) {     struct _stat buf;

if(ac != 2) {        printf("Usage: %s <FileName>\n",av[0]); return -1; }

/* Get File Statistics for stat.c. */ if( _stat( av[1], &buf ) != 0 ) perror( "Problem getting information" ); else /* print the date/time last modified */ printf( "Date/Time modified : %s", ctime( &buf.st_mtime ) ); }  /* End stat.c. */

Steps to reproduce the behavior (must be an NTFS drive)

 * 1) Open the Date/Time Properties dialog box and ensure that "Automatically Adjust For Daylight Saving Time" is selected. Press OK.
 * 2) Set your system date to a date that is during daylight saving time (for example, 10/25/97 in the "Pacific Time (US & Canada); Tijuana" time zone).
 * 3) Create a new file called repro.txt.
 * 4) Note the date/time last modified for repro.txt, as reported by either the Windows Explorer or using an MS-DOS dir command.
 * 5) At the MS-DOS prompt, run "c:\>stat.exe repro.txt", and note that the date/time last modified matches the date/time last modified that the system reports.
 * 6) Reset your system date to a date that is in the standard time period.
 * 7) Look again at an MS-DOS dir command (or in the Windows Explorer) and you can see that the time last modified for repro.txt is now one hour earlier than before.
 * 8) Repeat step 5, and note that the date/time reported by stat.exe is also one hour earlier, matching what the operating system reports.
 * 9) Clear "Automatically Adjust for Daylight Saving Time."
 * 10) Repeat steps 7 and 8, noting that the adjustment is not being made, and the time last modified has returned to its original value.

A similar series of steps can be followed to observe the time being adjusted forward one hour by creating the file during standard time and referencing it after the switch to daylight saving time.

Additional query words: _stat, _fstat, _findfirst, _findnext, NTFS

Keywords: kbtshoot kbcode kbprb KB190315

-

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

© Microsoft Corporation. All rights reserved.