
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 11:07 AM
Hi Team,
I need to set below value in glide_duration type field. Please let me know how to set this value into Duration field:
Time = 100 (minutes)
How to set this 100 mins into Duration field.
I tried like below, but, the vaqlue is not set into duration field.
current.time_worked = new GlideDuration('100');
Please suggest and provide proper way/script to set minutes value into Duration field.
Thanks & Regards,
Prasanna Kumar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2022 09:55 AM
the following worked for me, I created a new field on my table with type 'glide_time'.
var xTable = new GlideRecord('x_snc_bctestappnew_app_table');
xTable.query();
while (xTable.next()) {
gs.info("u_time = " + xTable.u_time + ".");
}
//new record
var numMinutes = 100;
var minutes = numMinutes%60;
var hours = (numMinutes - minutes)/60;
var timeVal = "1970-01-01 " + hours.toString() + ":" + minutes.toString() + ":00";
gs.info("timeVal = " + timeVal + ".");
xTable.initialize();
xTable.u_time = timeVal;
xTable.u_name = "New record";
xTable.insert();
you need extra logic if your value of minutes that you start with is greater than 1440 (one day).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 11:24 AM
//Try this
var dur = new GlideDuration('0 01:40:00'); //100 mins = 1 hr + 40 mins
recGR.<duration_field> = dur;
Vinod Kumar Kachineni
Community Rising Star 2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 11:41 AM
Thank you Vinod for your quick response. But, im trying to set time value dynamically. In one of my calculation, I got 100mins. How do we convert this 100 mins into 1hr 40 mins?
For example, if I get 40mins as answer, how to set this value dynamically into duration field. Please suggest the solution in that way.
Thanks & Regards,
Prasanna Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 12:09 PM - edited ‎11-27-2022 12:14 PM
Something like this??
var durStart = new GlideDateTime(gs.nowDateTime());
var durEnd = new GlideDateTime(gs.nowDateTime());
gs.print(durStart);
durEnd.addSeconds(1800); //From your calc minutes expressed as seconds 30 min * 60 sec = 1800 sec
gs.print(durEnd);
var duration = GlideDateTime.subtract(durStart, durEnd);
gs.print(duration.getDisplayValue());
//recGR.<duration field> = duration;
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2022 12:22 PM
var numMinutes = 100;
var minutes = numMinutes%60;
var hours = (numMinutes - minutes)/60;
gs.info("numMinutes = " + numMinutes + " = " + hours + " hours and " + minutes + " minutes.");
gives:
*** Script: numMinutes = 100 = 1 hours and 40 minutes.