Convert Time Type Field into Seconds

Roshani
Tera Expert

Hi All,

I have a field "u_abc" which is of Time Type and i want to convert that field values to seconds.

Example I have 10 HH: 00 MM: 00: SS

attached the screenshot .

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So what script did you use?

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur ,

I am using below script but its giving incorrect value . 

Also , new GlideDateTime(current.u_abc) is giving : some other time 18:00:00 . not the current time on form (10:00:00)

var time = new GlideDateTime(current.u_abc).getNumericValue()/1000;

 

Mahendra RC
Mega Sage

Hello Roshni,

Could you please check with below script:

The time in seconds should be correct. You can once check with .getDisplayValue() method and it should give the datetime present on form.

if you directly check the time like gs.print(gdt) then the time is return in GMT timezone I think and gdt.getDisplayValue() or new GlideDateTime(current.getValue("u_abc")).getDisplayValue() will return time in timezone set by user on the instance.

var gdt = new GlideDateTime(current.getValue("u_abc"));
var time = gdt.getNumericValue() / 1000;
gs.print(gdt.getValue());
gs.print(gdt.getDisplayValue());

Please mark my respsone as helpful/correct, if it answer your question.

Thanks

 

 

 

Hello Roshni,

Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.

If you still need any further help or guidance on this then please update those on this question.

Thanks