How to convert Duration to Seconds

devspider44
Giga Contributor

Is it possible to convert duration to seconds?

 

The real problem I have is this.

I have fields something like these on the form:

 

Start Date: (datetime field)

End Date:(datetime field)
Duration: (duration field)

 

On Duration change, I need to validate that the Duration field should not be longer than the duration between Start Date and End Date field. To do so when Duration field changes, I calculate duration between Start Date and End Date using the AjaxDurCalc script include:

 

gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);

 

and then compare it to the Duration field to check if the new value of Duration field is "lesser" than the in between duration of the Start and End dates.

 

There is no problem when the duration of Start and End date is more than a day.

 

For example:

 

Start Date: 21-07-2014 20:10:00
End Date: 22-07-2014 20:14:00
Duration: '2 00:00:00'

 

The output of AjaxDurCalc here is '1 00:04:00'. Then, if I evaluate (Duration > AjaxDurCalc), the output will be true since   '2 00:00:00' > '1 00:04:00'. If I change the Duration to '1 00:00:00', then the output will be false as expected since it is less than '1 00:04:00'.

 

The problem is when the AjaxDurCalc is less than '1 00:00:00', it evaluates wrongly when compared to a less than '1 00:00:00' Duration value.

Example, if I change the End Date from the previous example to the same date of Start Date and also set the Duration with 1 hour:

 

Start Date: 21-07-2014 20:10:00

End Date: 21-07-2014 20:14:00

Duration: '0 01:00:00'

 

AjaxDurCalc result is '00:04:00' (I noticed that the day value number is not present here)

 

I'm receiving a wrong result. If I evaluate '0 01:00:00' > '00:04:00' its giving me a false output which is not acceptable.

 

Am I missing something here? That's why I resorted if I can just convert both duration to seconds then compare it.