Wednesday, April 14, 2010

Windows fun with LastModified time

Here's an interesting thing I noticed yesterday. I only tried it on Windows 7, so perhaps the behavior is different on other versions of Windows. Also, this behavior seems to be specific to situations where Daylight Saving Time applies, so if your computer isn't observing Daylight Saving Time, you probably won't notice this.

Anyway, without further ado:

  1. Open Windows Explorer and find a file somewhere on your machine which you worked on back in February. It can be any file: a document, a picture, etc.

  2. In Windows Explorer, right-click on that file and choose Properties.

  3. Now, run the Command Prompt. (Start -> Run, and type "cmd"). Change directory to the folder where you found the file from February, and type "dir" to display the directory information.

  4. Now, tell me:

    Does the last-modified time displayed by the "dir" command match the last-modified time displayed in the "Properties" window?

On the systems that I tried it on, the DIR command displays a last-modified time that is 1 hour later than the time showed in Windows Explorer (which, I think, is the correct time).

If you happen to have a system running a version of Windows other than Windows 7, I'd appreciate it if you tried this experiment and let me know what you found.


  1. As far as I remember there was a bug (well known) in the old posix-like API, it may still be there (it became a feature ;) on some systems.

    However using the native API (GetFileInformationByHandle* in this case) solves this problem. That's what the explorer uses.

  2. Microsoft Windows XP [Version 5.1.2600]; modified times match (modified, accessed, and created).

    Bonus question: try this experiment with files at various times in March, using various locales. It would be interesting to see if the recent (few years ago) change in US DST setback time (versus most of Europe) left any bugs when taking files from one locale to the other when they're on opposite sides of the savings time.