Results 1 to 15 of 15
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the timestamp of a file on my hard drive

    Is your PC set to Toronto time (EST) or to London time (GMT / UTC)?

    My PC is set to Middle European Time (GMT+1), and if I use dtOffset = -1 / 24, your code sets the file date/times correctly.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change the timestamp of a file on my hard drive

    >Is your PC set to Toronto time (EST) or to London time (GMT / UTC)?
    Yes (grin)

    I'm set to (GMT-5.00) Eastern time (US & Canada).

    >My PC is set to Middle European Time (GMT+1), and if I use dtOffset = -1 / 24, your code sets the file date/times correctly.
    The Netherlands being one hour ahead of UTC, right? Just as I am 5 hours behind UTC.

    The System Time then is using my (Control Panel) date/time settings to adjust my local time to a globally unique time. If you (in Netherlands) and I (in Toronto) save a file (in the regular manner) at the same time, for example, by agreement during a telephone dialogue, our Windows Explorer screens will show a 6-hour time difference.

    But without the dtOffset patch, my code, if used by us both, would mark the saved file with an common time.

    If you run my code without your dtOffset value of -1/24, then the code would use +1/24 and you would appear to be living in Athens or Beirut?

    There seems to be something I've not understood here. If I release my code around the world without the dtOffset then code users who save files will see weird times appearing in the Windows Explorer screens.

    Of course, my code could set the dtOffset value automatically by using the user's time zone settings, but this all seems over complicated, a double-compensation of time zones where none is needed..

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the timestamp of a file on my hard drive

    If I use your code without the offset of -1/24, the file time is set to my time + 1 hour = GMT + 2 hours (Athens, Beirut, Pretoria, ...)

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change the timestamp of a file on my hard drive

    >If I use your code without the offset of -1/24, the file time is set to my time + 1 hour = GMT + 2 hours (Athens, Beirut, Pretoria, ...)
    Oh good. Thanks for the corroboration, and I'm sorry you had to go so far out of your way.(grin!)

    So the time stamps on files are held in a global-standard system time (that's the 64-bit value), but Windows Explorer, bless its little cotton socks, carefully adjust the display so that we see the system time adjusted by our local (Control Panel) regional time offset.

    If so that would mean that a VBA utility function whose job is to set the timestamp should make use of the local (Control panel) regional time offset; it is not enough to use, as an example "Now()".

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the timestamp of a file on my hard drive

    See Time Zones And Daylight Savings Time for info about getting time zone info.

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the timestamp of a file on my hard drive

    Hi Chris
    What libraries were necessary as references to allow this code to run in VBA. I get errors caused by at least the following: <UL><LI>FILETIME;
    <LI>DateToFileTime; and
    <LI> OFSTRUCT[/list]T.I.A.
    Regards
    Don

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the timestamp of a file on my hard drive

    Have you looked at Chris's attachment? That gives the complete code; the subs in the post itself are just the 'top-level' procedures.

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the timestamp of a file on my hard drive

    Oops <img src=/S/exclamation.gif border=0 alt=exclamation width=15 height=15>

    Thank you Hans.
    Regards
    Don

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change the timestamp of a file on my hard drive

    I initially fell into the same trap... <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

  10. #10
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the timestamp of a file on my hard drive

    Now that it runs, I will see if I can understand it. Thanks again. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Regards
    Don

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change the timestamp of a file on my hard drive

    I would like to know why I get a -5 offset in time values, which I don't expect.

    The attached module, borrowed from another web site, aims to change the timestamp of a file on my hard drive.
    I understand the concept of a structure to manipulate a 64-bit quantity, but I'm puzzled that at noon today, without my "dtOffset" code, the timestamp changed to be 7am, as if I lived somewhere in the Pacific Ocean, two hours west of Vancouver.
    I'm accustomed (in Toronto) to seeing 5pm when it's noon here; I shrug and say "OK, that's like the old UK GMT", but the Pacific Ocean ????

    <pre>Public Sub SetFileTimesEx(sFile As String, dateCreated As Date, dateLastAccessed As Date, dateModified As Date)
    Dim hFile As Long, rtn As Long
    Dim ftCreated As FILETIME, ftLastAccessed As FILETIME, ftModified As FILETIME
    Dim dtOffset As Date
    dtOffset = TimeValue("05:00:00") ' Correction for EST (Toronto)
    ftCreated = DateToFileTime(dateCreated + dtOffset)
    ftLastAccessed = DateToFileTime(dateLastAccessed + dtOffset)
    ftModified = DateToFileTime(dateModified + dtOffset)
    Dim OFS As OFSTRUCT
    OFS.cBytes = Len(OFS)
    hFile = OpenFile(sFile, OFS, &H1)
    If hFile > 0 Then
    rtn = SetFileTime(hFile, ftCreated, ftLastAccessed, ftModified)
    rtn = CloseHandle(hFile)
    End If
    End Sub
    Sub TESTSetFileTimesEx()
    Call SetFileTimesEx("G:GreavesProductsDEVELWbWrdwhatfaq .doc", Now(), Now(), Now())
    End Sub</pre>

    Attached Files Attached Files

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change the timestamp of a file on my hard drive

    >for info about getting time zone info.

    Thanks Hans.

    dtOffset = LocalOffsetFromGMT(True) seems to do the trick.

    Hans and Don: "I initially fell into the same trap.."
    Sorry. I might have highlighted "The attached module" (done now)

  13. #13
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the timestamp of a file on my hard drive

    Hi All
    I would have expected the third argument in the TESTSetFileTimesEx procedure to control the file's Accessed property, but I think that you will find it is set to coincide with the command " rtn = SetFileTime(hFile, ftCreated, ftLastAccessed, ftModified) " firing.
    Regards
    Don

  14. #14
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Change the timestamp of a file on my hard drive

    Chris
    I smell a rat.
    I suggest that you download Chip Pearson's Time Zones And Daylight Savings Time module; then run the following command from your Immediate window.

    <center> ?LocalOffsetFromGMT(True) </center>

    Since you are in the same time zone as me you should have 5 returned.
    Regards
    Don

  15. #15
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change the timestamp of a file on my hard drive

    >I suggest that you download Chip Pearson's ...
    <post:=751,506>post 751,506</post:>
    I beat you to it by a (rat's) whisker! <img src=/S/mice.gif border=0 alt=mice width=50 height=25>
    Thanks Don for doing a parallel run.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •