Skip navigation
Currently Being Moderated

How do I convert a hex date?

Feb 21, 2014 12:35 PM

Tags: #date #hex #cf10 #cfsharepoint

When outputting meta data from SharePoint Foundation 2010 using cfsharepoint I am noticing datetimes are being converted to the following format:  0x01cf2d81|0x71c80a00

 

How do I convert this to a regular date using ColdFusion?  I have found some references to this issue here http://sharepoint.stackexchange.com/questions/66602/dates-and-times-in -properties-vs-fields/91069#91069 which shows a solution like this:

 

 

//fieldValue looks like "0x01cf2f8e|0x6e559e00"
string fieldValue = listItem.Properties[dateFieldName]
string hexValue = fieldValue.Replace("|", "").Replace("0x", "");
long ticks = long.Parse(hexvalue, NumberStyles.HexNumber);

DateTime date1 = DateTime.FromBinary(ticks).AddYears(1600);

 

But I have no idea how to do this in ColdFusion.  Apparently the hex value represents the number of ticks since 1st Jan 1600.  Crazy, I know.

 

Any ideas??  Thanks.

 
Replies
  • Currently Being Moderated
    Feb 22, 2014 5:17 AM   in reply to DCwebGuy

    <!---

    Assumption: 0x01cf2f8e|0x6e559e00 stands for the Hex number 1cf2f8e6e559e00. That is the number of ticks.

    --->

    <!--- Conversion of the number of ticks, 1cf2f8e6e559e00, from Hex to Base 10, remembering that F=15, E=14, D=13, C=12, etc  --->

    <cfset numberOfTicks = 14*16^2+9*16^3+5*16^4+5*16^5+14*16^6+6*16^7+14*16^8+8*16^9+15*16^10+2*16^11+15*16^12+12*16^13+1*16^14>

     

    <!---

    By definition,

     

    1 second = 10 000 000 ticks.

    --->

    <cfset numberOfWholeMinutes = round(numberOfTicks/(10000000*60))>

     

    <!--- Starting datetime is 1st January 1600 --->

    <cfset zeroDateTime=createdatetime(1600,1,1,0,0,0)>

     

    <cfset newDateTime=dateadd("n",numberOfWholeMinutes,zeroDateTime)>

     

    <cfoutput>#newDateTime#</cfoutput>

     

    My answer is: 2013-02-21 05:25:00

     

     

    [Sidenote: I attempted to use the function inputBaseN("1cf2f8e6e559e00",16) to convert from Hex to base 10, but it gave the wrong result! I will now report this as a bug. I would suggest that you write your own function to do the conversion.]

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 22, 2014 5:44 AM   in reply to BKBK

    BKBK wrote:

     

    Sidenote: I attempted to use the function inputBaseN("1cf2f8e6e559e00",16) to convert from Hex to base 10, but it gave the wrong result! I will now report this as a bug.

     

    If you wish to vote or comment, the link is: https://bugbase.adobe.com/index.cfm?event=bug&id=3712098

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2014 10:23 PM   in reply to DCwebGuy

    <cfset newDateTime = dateadd("n",numberOfWholeMinutes,"01/01/1601 12:00 AM")>

    The 3rd argument of the dateAdd function should be a datetime object. So you could improve it with something like this

     

    <cfset newDateTime = dateadd("n",numberOfWholeMinutes,createdatetime(1601,1,1,0,0,0))>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points