ServiceNow GlideDateTime() – Get The Current Date And Time

Scripting around dates and time in ServiceNow has caused every ServiceNow Engineer some pain at a certain point. Here’s how to get the current date and time in ServiceNow. This will be a super simple …

Buy The 'ServiceNow Developer Manual' Here!

Snowball - ServiceNow Developer Manual

Newsletter Signup

Want to get better at ServiceNow?
(One email per month, no fluff - only value)

get the current date and time



Buy The "ServiceNow Developer's Manual" Now

We've packed over a decade of ServiceNow Development advice, into a single e-book.



Scripting around dates and time in ServiceNow has caused every ServiceNow Engineer some pain at a certain point.

Here’s how to get the current date and time in ServiceNow.

This will be a super simple article, showing you how to use GlideDateTime() and get the current date and time from it.

When you’re using the GlideDateTime() object, you’re limited to ServiceNow’s methods to retrieving date time information, which a lot of people complain about.

To just print the current date and time in a single method, use:

gs.nowDateTime();

Alternative to the GlideDateTime() class, you can use the JavaScript Date() object, which has more methods to retrieve helpful information from.

/* GlideDateTime */
/* Get the current time */

var gdt = new GlideDateTime();
var date = gdt.getDate();
var time = gdt.getTime();
gs.print("date: " + date);
gs.print("time: " + time);
gs.print("gs.nowDateTime(): " + gs.nowDateTime());

When you run the following script in a background script in ServiceNow, you will get the following output:

Give the above example a try in a background script.

This will work in any server side script, so a business rule or script include.

The above example will not work in any client side scripting.

Leave a Comment

Product Image

Patrick just purchased A ServiceNow Developer’s Manual 20 Hours ago from Omaha NE.

Buy Now