Has anyone successfully converted a FILETIME date/time value into a MM/DD/YYYY format using ColdFusion? I am failing drastically, and it seems like an easy conversion.
FILETIME format (details: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs. 85).aspx) is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
A database I'm working with has such values, and I want to display them in a user-friendly date format within my application.
For example, one record is:
The above number represents the following date and time:
1/22/2013 @ 2:50 PM
Sadly I know this only because the FILETIME value gets written to the database by a third-party application, and within that application I specify it in the MM/DD/YYYY format.
Can anyone offer me some guidance, or better yet has anyone accomplished this already and want to share code?
Do it step by step.
First - divide by something to convert the filetime to seconds.
Next - do a dateadd to 1601-01-01
Finally, format the date.
Note - I did a quick google search and could not find the minimum allowed date in cf. If it's later than 1601-01-01, it's just a couple of extra steps.
I did this, on cf9/linux, and it seemed to do the trick:
Long = createObject("java","java.lang.Long");
Date = createObject("java","java.util.Date");
// take pwdLastSet From Active Directory, it's in filetime
pwdLastSet = JavaCast("long", Long.parseLong("130292682204519505"));
// take filetime and turn it into epoch/java - 1970/1/1
// http://www.silisoftware.com/tools/date.php - converted: jan 1, 1970 00:00 -00
javaTime = JavaCast("long", pwdLastSet - 116444736000000000);
// convert to milliseconds
javaTime = JavaCast("long", javaTime / 10000);
today = JavaCast("string", Date.init(javaTime));