This function generates a 14-digits unique number that you may need when you assign unique IDs/numbers for database records.
<cffunction
name="nowToNumber"
access="private"
returntype="numeric"
output="false"
hint="This function generates a 14-digit unique number from the current date and time">
<cfparam name="result" default="0">
<!---
get the year, month, day, hour, minute, and second from the current date/time and store them in variables
--->
<cfset vYear=year(now())>
<cfset vMonth=month(now())>
<cfset vDay=day(now())>
<cfset vHour=hour(now())>
<cfset vMinute=minute(now())>
<cfset vSecond=second(now())>
<!---
check the length of the month, day, hour, minute, and second. if the length is less than 0 then store "00" into the variables, if the
length is 1 then append "0" to the beginning of the variable value. this is to ensure that the generated number is 14-digits.
--->
<cfif len(vMonth) EQ 0>
<cfset vMonth="00">
<cfelseif len(vMonth) EQ 1>
<cfset vMonth="0" & vMonth>
</cfif>
<cfif len(vDay) EQ 0>
<cfset vDay="00">
<cfelseif len(vDay) EQ 1>
<cfset vDay="0" & vDay>
</cfif>
<cfif len(vHour) EQ 0>
<cfset vHour="00">
<cfelseif len(vHour) EQ 1>
<cfset vHour="0" & vHour>
</cfif>
<cfif len(vMinute) EQ 0>
<cfset vMinute="00">
<cfelseif len(vMinute) EQ 1>
<cfset vMinute="0" & vMinute>
</cfif>
<cfif len(vSecond) EQ 0>
<cfset vSecond="00">
<cfelseif len(vSecond) EQ 1>
<cfset vSecond="0" & vSecond>
</cfif>
<!---
concatenate the variables in the format "YYYYMMDDHHMMSS" and return the result.
--->
<cfset result = vYear & vMonth & vDay & vHour & vMinute & vSecond>
<cfreturn result>
</cffunction>
<cfoutput>#nowToNumber()#</cfoutput>