- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 09:31 AM
I have an integer field that stores the value of two dates in seconds.
I would like to convert this integer field (seconds) into a duration field.
For example, result of the two dates is 150000.
How can I convert into a duration field to display as seconds, minutes, hours, days.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 11:41 AM
I tried a client script for this so that as soon as you change the value of the integer it change the duration also:
Integer field is : u_integer_1
Duration field is : u_glide_duration_2
on change of integer Script is something like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var inputSecondstemp = (g_form.getValue('u_integer_1'));
var inputSeconds = parseInt(inputSecondstemp, 10);
//old school get the variables in place
var secondsInAMinute = 60.0;
var secondsInAnHour = 60.0 * secondsInAMinute;
var secondsInADay = 24.0 * secondsInAnHour;
// extract days
var days = Math.floor(inputSeconds / secondsInADay);
// extract hours
var hourSeconds = inputSeconds % secondsInADay;
var hours = Math.floor(hourSeconds / secondsInAnHour);
// extract minutes
var minuteSeconds = hourSeconds % secondsInAnHour;
var minutes = Math.floor(minuteSeconds / secondsInAMinute);
// extract the remaining seconds
var remainingSeconds = minuteSeconds % secondsInAMinute;
var seconds = Math.ceil(remainingSeconds);
var duration = (days.toString() + " " + hours.toString() + ":" + minutes.toString() + ":" + seconds.toString());
g_form.setValue('u_glide_duration_2', duration);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 09:49 AM
Hello John
Try this:
function sec2str(t){
var d = Math.floor(t/86400),
h = ('0'+Math.floor(t/3600) % 24).slice(-2),
m = ('0'+Math.floor(t/60)%60).slice(-2),
s = ('0' + t % 60).slice(-2);
return (d>0?d+'d ':'')+(h>0?h+':':'')+(m>0?m+':':'')+(t>60?s:s+'s');
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 10:59 AM
Prateek, that worked perfectly. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 11:21 AM
Awesome john. Glad it worked for you. Cheers
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2018 02:56 AM
Hi Prateek ,
Where is this script supposed to be written ?