- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2025 01:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2025 08:12 AM
Hi @Helan Try below script I try in background script
var dt = new GlideDateTime();
gs.print("Current Date and Time: " +dt);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2025 07:08 AM
Hello @Helan ,
Your question is ambiguous.
Are you talking about a JavaScript variable in a script? If so, is is a Client Script or a server side one?
Or are you referring to a Variable (question) on a Catalog Item?
Randomly assuming you are talking about a server script, here is the answer:
var now = new GlideDateTime();
gs.info(now.getDisplayValue());
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2025 10:02 PM
@Helan What is the concern with this answer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2025 10:16 PM
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2025 05:18 AM - edited ‎05-26-2025 05:21 AM
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