Helan
Tera Contributor
  • Thanks for your help @Robert H @! Your script worked,but it gave yesterday’s date. I needed the current date and time, so I accepted the other answer. Appreciate your support

 

 

Hello @Helan ,

 

Actually, all solutions presented here will give you the current date and time.

The difference is the time zone that this time is interpreted in.

 

My solution prints the date/time as per the time zone selected in the current user's profile. If you have not set your time zone correctly e.g. it's set to US/Pacific but you're actually located in India you will sometimes see yesterday's date. If you update your time zone setting to IST then the above code will print your exact local date and time.

 

The other solutions print the date/time as per the UTC time zone. This is IST -5:30 hours. So if you use that solution in the very early morning it will also print yesterday's date.

 

Regards,

Robert

Harish Bainsla
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

Thanks @Harish Bainsla ! This worked for me

Harish Bainsla
Kilo Patron

Please accept solution if it helps you