We are working with millisecond conversion of time duration which is saved in database (Format : mm:ss ).The duration value we can access through the command #bignews.Control_CountdownDuration#.
<div class="slideBox" data-duration="#bignews.Control_CountdownDuration#">
The current value(mm:ss) is not sufficient for proper working of data-duration. Can anyone guide me to complete the task ?
A comination of createTimeSpan()
and dateDiff()
will do the job.
Input here goes into the variables minutes
and seconds
:
<cfset cmpBase = createTimeSpan(0, 0, 0, 0)>
<cfset cmpValue = createTimeSpan(0, 0, minutes, seconds)>
<cfset diffInSeconds = dateDiff("s", cmpBase, cmpValue)>
<cfset diffInMilliseconds = (diffInSeconds * 1000)>
Assuming your source value is stored as string like mm:ss
, this would be:
<cfset minutes = getToken(bignews.Control_CountdownDuration, 1, ":")>
<cfset seconds = getToken(bignews.Control_CountdownDuration, 2, ":")>
<cfset cmpValue = createTimeSpan(0, 0, minutes, seconds)>
<cfset cmpBase = createTimeSpan(0, 0, 0, 0)>
<cfset diffInSeconds = dateDiff("s", cmpBase, cmpValue)>
<cfset diffInMilliseconds = (diffInSeconds * 1000)>
<div class="slideBox" data-duration="#diffInMilliseconds#">
(Validation left out for readability.)
On a side note: You should probably work with the total number of seconds (see variable diffInSeconds
) since you don't have the milliseconds precision anyway.