- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2014 03:04 PM
Hi ServiceNow Community Developers,
If I am looking for todays date i.e. current date I can use gs.NowDateTime on a business rule or on a script include. Any idea how I can get the current date using a client script. Please advise.
Thanks,
Johannes
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2014 03:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2014 03:12 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2014 07:07 PM
Try this:
var ajax = new GlideAjax('MyDateAjax');
ajax.addParam('sysparm_name','nowDate');
ajax.getXMLWait();
var rightnow = ajax.getAnswer();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2014 01:25 PM
Hi Johannes,
If you want to retrieve the date from the client's time settings, you can use a client script with the following:
var today = new Date();
var displayDate = today.getDate()+'-'+today.getMonth()+'-'+today.getFullYear();
OUTPUT: 7-11-2014
The Date class has a heap of methods for setting or getting parts of the date/time. If you open the developer tools Javascript console in Chrome and type "today.", the autocompleter list will show all of the available methods (see the screen cap below as an example).
If you need the date value from the server, I would recommend getting the date in a Display Business Rule (e.g using gs.getNowDateTime()), then adding it to the scratchpad (e.g g_scratchpad.todayDate = gs.getNowDateTime().toString(); ) and then retrieving this in your client script (refer to g_scratchpad.todayDate in your client script).
Regards,
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2014 04:19 PM
Hi ServiceNow Developers,
Thank you very much for all your responses, they were all correct. I was actually amazed that this can be done in so many different ways.
Thanks,
Johannes