Skip to main content
Known Participant
February 23, 2012
Question

Creating windows filetime value from current date/time

  • February 23, 2012
  • 2 replies
  • 2473 views

We are working with a vendor database that stores the date/time of a scheduled event in Windows Filetime format in MSSQL in a field defined as float (8)

example: 129744036000000000 is in the database and represents the date time of 2/21/22 9:00am

I have found a solution to converting that data to a readable format of date/time for displaying to users, it is listed below

<cfset objJava = createObject("java","java.util.Date")>

<cfset dateJava = objJava.init(javacast("long", (129744036000000000-116444736000000000)/10000))>

This works very well.

Now my next challenge that I have not found a solution for is how to convert the current date/time to Windows filetime value, in essance the revers of the above.

For example, I need to convert the date/time a person chooses as the start date/time to the Windows filetime format for inserting backinto the db.

Vendor, offers no API or docs on this either.

Thanks

    This topic has been closed for replies.

    2 replies

    DgcottonAuthor
    Known Participant
    February 25, 2012

    MW, I would not disagree at all and that is what is bugging me. I am not epxert by any means but this seems too simple.

    Here is my test:

    <cfset Date_1 = "02/22/2012 9:00 AM">

    <cfset Date_2 = "01/01/1601 12:00 AM">

    <cfset Date_3 = DateDiff("s", #Date_2#, #Date_1#)>

    Date_3 end up being 89472912. Now I know I need to add a muliplier for the 100 nanoseconds, but it isn;t going to end up with the right type of value as aI know 129744036000000000 is in the database and represents the date time of 2/21/22 9:00am

    The number should be starting with at least "12974".

    I am sure I am having a brain freeze here on this

    BKBK
    Community Expert
    Community Expert
    February 25, 2012

    Dgcotton wrote:

    MW, I would not disagree at all and that is what is bugging me. I am not epxert by any means but this seems too simple.

    Here is my test:

    <cfset Date_1 = "02/22/2012 9:00 AM">

    <cfset Date_2 = "01/01/1601 12:00 AM">

    <cfset Date_3 = DateDiff("s", #Date_2#, #Date_1#)>

    Date_3 end up being 89472912. Now I know I need to add a muliplier for the 100 nanoseconds, but it isn;t going to end up with the right type of value as aI know 129744036000000000 is in the database and represents the date time of 2/21/22 9:00am

    The number should be starting with at least "12974".

    The number does in fact start with 12974. You mistakenly used 02/22 instead of 02/21.

    DgcottonAuthor
    Known Participant
    February 25, 2012

    So I used the other date/time creatuion suggestion and fixed the date to 2/21 as below

    <cfset date_1 = createdatetime(2012,2,21,9,0,0)>

    <cfset date_2 = createdatetime(1601,1,1,0,0,0)>

    <cfset Date_3 = DateDiff("s", #Date_2#, #Date_1#)>

    When I display the value of Date_3 it is Date_3: 89386512

    Is my Datediff correct? I know it is in seconds and to convert to nanoseconds I would multiply that by 1000000000.

    But still the starting numbers should be 12974 not 8938.

    .....Still confudsed....

    February 24, 2012

    Hi Dg.  I'll answer this, but this is something as a developer you should be able to solve on your own.  A quick google search of "Windows Filetime" reveals that the number represents the number of 100-nanoseconds since Jan 1, 1601.  So take your input date, do a datediff to get the number of seconds since 1/1/1601, then multiply by a factor that converts seconds to 100-nanoseconds.