Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

ServicePortal: How can I default a Date/Time field to show current date & time?

MWright1
Giga Guru

I have a Date/Time field in one of the RITM that I need to default to current date/time.

Using javascript: gs.now(); fills in the Date but the time is 00:00:00.

 

MWright1_0-1746471419954.png  

MWright1_1-1746471537021.png

 

I have tried using : javascript: new Date().toLocaleString();

However, it ends up giving me a weird time.  

It can't be this difficult to just have a default date & time...!  Please help.

 

1 ACCEPTED SOLUTION

J Siva
Kilo Patron
Kilo Patron

Hi @MWright1 
Try the below script in the default value.

javascript:new GlideDateTime().getDisplayValue();

Regards,
Siva

View solution in original post

4 REPLIES 4

J Siva
Kilo Patron
Kilo Patron

Hi @MWright1 
Try the below script in the default value.

javascript:new GlideDateTime().getDisplayValue();

Regards,
Siva

Thank you very much!

Ankur Bawiskar
Tera Patron
Tera Patron

@MWright1 

to see the now time in the logged in user's timezone use this

javascript: var dateTime = new GlideDateTime().getDisplayValue(); dateTime;

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

J Siva
Kilo Patron
Kilo Patron

@MWright1 Glad it helped.