To get time from glide date time

joshishree
Kilo Contributor

I am not getting the time field from the below code as i have to set it to 08:00:00 how should i do it. next day date i am getting properly how to get the time.And then return the complete date and set the field in client script.

find_real_file.png

10 REPLIES 10

Sadasiva Reddy
Giga Guru

Hi Joshi,



Use below code for time..



var gg = new GlideDateTime();



gs.print('gg'+gg);



var str = gg.toString();



var dateSplt = str.split(' ');


var time = dateSplt[1];




gs.print('hello'+ time);



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response is useful.



Regards,


Sadasiva


Sadasiva Reddy
Giga Guru

In the above code...


var dateArr = str.split('(here it is space) ');


joshishree
Kilo Contributor

yup its working the date format for the planned start date fields are in dd:mm:year format after the script is running its converting into yy:mm:dd what should be done to keep it in current format .where should i make changes


Dennis R
Tera Guru

Hi Bhagyashree, there's a GlideTime function getByFormat you can use:



var gg = new GlideDateTime();


gg.addDays(1);


var date = gg.getDate();


var time = gg.getTime();


gs.addInfoMessage(date);


gs.addInfoMessage(time.getByFormat('HH:mm:ss'));


gs.addInfoMessage(gg);



A couple of notes:


  • The documentation suggests not using addDays; use addDaysLocalTime or addDaysUTC instead.   This will account for Time Zone changes and oddities.
  • This shows the time in the default system time zone, probably UTC.   If you want it to show your local time, use getLocalTime() instead of getTime().

Jafet
Kilo Explorer

I need help with something, I have a field that is a string where a enter numbers for a time to completion of a Knowledge Article. I need to change that field to a GlideDuration field, so I need to convert all the Knowledge Articles that has the time in a string to a glideDuration how can I do that with a script? 

Thanks in advance.