Skip to content

Instantly share code, notes, and snippets.

@JamoCA
JamoCA / DateHash_Unhash.cfm
Last active September 6, 2022 23:16
ColdFusion UDF to format a date/time value to string format "yyyymmddHHmmssll" and back again. #dateHash(Now())# #dateUnHash("20140704")#
<cfscript>
/* 1/24/2011 james Moberg [email protected]
@param numberofChars, number of characters (Optional, 12 = default)
@param d, date/time string or object (Optional, now() = default)
@return Returns a yyyyMMddHHmmssll string (depending on length of numberofChars.)
Updated 20220903 to support millisecond */
string function dateHash(numeric numberofChars=12, date=now()) hint="I convert a date object to yyyymmddHHmmssll" {
var response = '';
if(not isvalid("date", arguments.date)) {
arguments.date = now();