VBA function FileDateTime() is off by 1 hour.

de33ed BS 0 Reputation points
2024-06-29T21:45:20.9966667+00:00

Assuming current date is 06/29/2024 (PDT) and timezone is Los Angeles, the following example is correct.


Dim MyStamp
' Assume TESTFILE was last modified on June12, 2024 at 4:35:47 PM.
' Assume English/U.S. locale settings.
MyStamp = FileDateTime("TESTFILE") ' Returns "6/12/24 4:35:47 PM".


However if TESTFILE was created/modified prior to or after Daylight Savings time, "MyStamp" is off by one hour.


Dim MyStamp
' Assume TESTFILE was last modified on February 12, 2024 at 2:15:47 PM.
' Assume English/U.S. locale settings.
MyStamp = FileDateTime("TESTFILE") ' Returns "2/12/24 3:15:47 PM".


So how to correct not knowing if DST was applied at file creation/modification time?

~ Thank you.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,680 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,683 questions
0 comments No comments
{count} votes