How to store today's date/time in a variable and print it

Helan
Tera Contributor

Hello,

How to store today's date/time in a variable and print it ?

1 ACCEPTED SOLUTION

Harish Bainsla
Kilo Patron
Kilo Patron

Hi @Helan Try below script I try in background script 

var dt = new GlideDateTime(); 
gs.print("Current Date and Time: " +dt); 

Screenshot 2025-05-24 at 8.40.00 PM.png

View solution in original post

8 REPLIES 8

Harish Bainsla
Kilo Patron
Kilo Patron

Hi @Helan Try below script I try in background script 

var dt = new GlideDateTime(); 
gs.print("Current Date and Time: " +dt); 

Screenshot 2025-05-24 at 8.40.00 PM.png

Thanks @Harish Bainsla ! This worked for me

Harish Bainsla
Kilo Patron
Kilo Patron

Please accept solution if it helps you 

Ankur Bawiskar
Tera Patron
Tera Patron

@Helan 

so you want current date/time in your date/time variable

If yes then you can use default value as this

javascript: new GlideDateTime();

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