Skip to content

Instantly share code, notes, and snippets.

@ciaranarcher
Created July 6, 2011 16:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ciaranarcher/1067745 to your computer and use it in GitHub Desktop.
Save ciaranarcher/1067745 to your computer and use it in GitHub Desktop.
Function to Convert a ColdFusion Date to a .NET Ticks Representation
<cffunction name="getTicks" access="public" returntype="numeric" output="false" hint="Returns the number of .NET ticks representing a the given date.">
<cfargument name="dateValue" type="date" required="true" />
<!---
http://msdn.microsoft.com/en-us/library/system.datetime.ticks(v=vs.71).aspx
http://stackoverflow.com/questions/386341/c-how-do-i-convert-ticks-to-minutes
--->
<cfset var ticksAtEpochZero = 621355968000000000 /> <!--- Number of .NET ticks at Epoch time (January 1 1970 00:00) --->
<cfset var ticksPerSec = 10000000 />
<!--- Get difference between Epoch time and the given date expressed as ticks --->
<cfset var ticksAtDate = dateDiff("s", "January 1 1970 00:00", ARGUMENTS.dateValue) * ticksPerSec />
<!--- Add this to our baseline ticks value --->
<cfset var ticks = (ticksAtEpochZero + ticksAtDate) />
<cfreturn trim(numberFormat(ticks, "99999999999999999")) />
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment