Announcement

Collapse
No announcement yet.

Windows FILETIME conversion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Windows FILETIME conversion

    I am writing a program to print out the OFFITEMS log from windows
    Included in the file are filenames with a 8Byte FILETIME next to the
    filename.

    I need to convert the 8 byte filetime (64bit) into a regular
    time and date we can all read.

    I am under the gun and would like to know if anyone has code to convert
    the 8bytes to regular date and time. I have the file layout figured out
    just not how the 8 bytes (64bits) work.

    ------------------

  • #2
    Don't suppose you are able to call a (Windows) console application which uses the FileTimeToSystemTime() API function to convert the integer into a date/time value?
    If you try to make something idiot-proof, someone will invent a better idiot.

    Comment


    • #3
      MSDN says, "The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC)." Fortunately, PB/DOS supports QUADs, so you can do this sort of calculation without too much trouble. To get the year, divide the file time by the number of 100-nanosecond intervals in a year, and add 1601. Take the remainder from this division, and divide it by the number of 100-nanosecond intervals in a month to get the month... etc.

      If you don't want the results in UTC, it will probably be easiest if you calculate the bias for local time as a QUAD value first, and apply it before you start all the other calculations. Otherwise, you're facing a cascade effect where adjusting the time may put you on a different day, which may mean adjusting the month, etc.

      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment


      • #4
        To get the year, divide the file time by the number of 100-nanosecond intervals in a year, and add 1601. Take the remainder from this division, and divide it by the number of 100-nanosecond intervals in a month to get the month... etc.
        Using this method to derive date components from an integer value is prone to error for the simple fact that both years and months have variable lengths. Making assumptions like this will introduce rounding errors, which will get worse the further away from 1601 you get.
        If you try to make something idiot-proof, someone will invent a better idiot.

        Comment


        • #5
          Good point-- although a good average value for the year interval will mostly overcome any rounding problems. We're talking about mighty small intervals.

          A search on "Julian" in the Forums here should turn up any number of examples.

          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            mark,

            i have just posted to the source code forum some code which should demonstrate how this can be done with pb/dos. see the thread convert a windows filetime value to a date string.

            hth
            If you try to make something idiot-proof, someone will invent a better idiot.

            Comment

            Working...
            X