Extract just time from the time_worked field

MBarrott
Mega Sage

I'm passing over the value from the time_worked field via g_scratchpad but noticed it is also passing over a placeholder date (e.g 1970-01-01 01:00:00).

 

g_scratchpad.savedTime = current.time_worked;

 

Is there a easy way to simply remove the date so that the passed over value is just "01:00:00"? 

1 ACCEPTED SOLUTION

sejal1107
Tera Guru

Hi @MBarrott 

g_scratchpad.savedTime = current.time_worked.toString().split(" ")[1]; 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers

Thanks,

Sejal

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan

View solution in original post

6 REPLIES 6

JenniferRah
Mega Sage

Try this

var gdt = new GlideDateTime(current.time_worked);
gt = gdt.getTime();
g_scratchpad.savedTime = gt.getByFormat('hh:mm:ss');

sejal1107
Tera Guru

Hi @MBarrott 

g_scratchpad.savedTime = current.time_worked.toString().split(" ")[1]; 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers

Thanks,

Sejal

Please check and Mark Helpful and Correct if it really helped you.
Thanks & Regards
Sejal Chavan

Hi @sejal1107 - perfect, thank you!

Bert_c1
Kilo Patron

Yes,

 

var ndt = new GlideDateTime();
var secs = ndt.toString().substr(11);
gs.info('ndt = ' + ndt + ', seconds = ' + secs);

results in:

*** Script: ndt = 2024-10-24 14:59:51, seconds = 14:59:51