Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:38:57+00:00 2026-05-30T00:38:57+00:00

I’m working on a program that records date metadata from files, such as creation

  • 0

I’m working on a program that records date metadata from files, such as creation time, last modified time, etc. An old version of the program is written in VBA, and does something like this:

Public Function GetFileLastAccessTime(ByVal FilePath As String) As Date
    Dim fso As New Scripting.FileSystemObject
    Dim f As Scripting.File
    Set f = fso.GetFile(FilePath)
    GetFileLastAccessTime = f.DateLastAccessed
End Function

Output for the file in question:

?getfilelastaccesstime("SomePath")
7/30/2010 2:16:07 PM 

That is the value I get from the file properties in Windows Exploder. Happiness.

I’m porting this functionality to a VB.Net app. The new code:

Public Function GetLastAccessTime(ByVal FilePath As String) As Date
    Return IO.File.GetLastAccessTime(FilePath)
End Function

Simplicity itself. The output:

?GetLastAccessTime("SomePath")
#7/30/2010 3:16:07 PM#

One hour later.

Both functions are running on the same machine, checking the same file. I’ve also tried using the IO.FileInfo class with the same result. I’ve checked thousands of files and they are all off by one hour. The other date properties for creation time and last modified time are also off by one hour.

Help!

I forgot to mention in the original post, The computer’s time zone is CST, and daylight savings time is currently not in effect.

I’ve reproduced the problem on Windows 7 64 bit and Windows XP 32 bit.

Thanks.

1/6/2011 update:

Thanks to everyone who suggested trying to calculate the desired date from UTC using the appropriate time zone offsets. At this time I’m deciding its not worth the risk to do so. For this particular business requirement, its much better to say the date value is not what you expected it to be because thats just the way the API works. If I attempt to “fix” this then I own it, and I’d rather not.

Just for kicks I tried using the good old Scripting.FileSystemObject via interop. It gives the expected results that agree with Windows Explorer, with about a 5x performance penalty compared to System.IO. If it turns out I must get dates that match what Windows Explorer has, I will bite the bullet and go this route.

Another experiment I tried was going directly to the GetFileTime API function in kernel32 via C#:

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetFileTime(
IntPtr hFile,
ref FILETIME lpCreationTime,
ref FILETIME lpLastAccessTime,
ref FILETIME lpLastWriteTime
);

That resulted in exactly the same behavior System.IO had, the time was off by an hour from Windows Explorer.

Thanks again everyone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:38:59+00:00Added an answer on May 30, 2026 at 12:38 am

    I can reproduce this using .NET 4.0 and 2.0/3.5 on XP/Win2k3/Vista.

    The issue is DST was in a different state to now, and .NET is processing this difference differently to Explorer and Scripting.FileSystemObject.

    (You can see a similar issue when extracting files from a zip file when DST is different to when the files were zipped.)

    Via Reflector, the reason .NET differs from the non .NET code paths is that all three local datestamps in IO.File (and IO.FileInfo) are implemented as getting the Utc datestamp and applying .ToLocalTime, which determines the offset to add based upon whether DST was happening in the local timezone for the Utc time.

    I also checked, by changing the date to July 1 last year, creating a file and watching the timestamp when I return to the current date (March 16) (I’m in South Australia, so we’re in DST now and were not on July 1), and Windows (and presumably FileSystemObject) adds the DST in place NOW so the time displayed actually changes.

    So, in summary, .NET is more correct.

    But if you want the incorrect, but same as Explorer, date use:

    Public Function GetLastAccessTime(ByVal FilePath As String) As Date
        Return IO.File.GetLastAccessTimeUtc(FilePath) _
          .Add(TimeZone.CurrentTimeZone.GetUtcOffset(Now))
    End Function 
    

    This has been discussed on Raymond Chen’s blog (where the summary is: .NET is intuitively correct but not always invertible, and Win32 is strictly correct and invertible).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.