1

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 ?

Süresh AK
  • 344
  • 3
  • 20

1 Answers1

2

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.

Alex
  • 7,743
  • 1
  • 18
  • 38
  • 4
    Looks much more complicated than necessary. To me the problem is as simple as splitting the string into minutes and seconds, mulitplying the minutes by 60, adding the seconds, and muliplying by 1000. – Dan Bracuk Dec 24 '15 at 11:48
  • I had used the second part of code of his answer to resolve the issue. – Süresh AK Dec 24 '15 at 16:45