
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:08 AM
I have a custom table with a Date/Time field named PressedButton.
This table also has an Integer field named Year, an String field named Month, and an Integer field named Day.
When I run this:
var nowdt = gs.nowDateTime();
var gr = new GlideRecord('u_my_custom_table');
gr.u_pressedbutton = nowdt;
gr.insert();
Everything works great. The record is inserted and the date/time field shows up perfectly.
I now want to populate the other fields with the breakdown of gs.nowDateTime(). For example:
var nowdt = gs.nowDateTime();
var gr = new GlideRecord('u_my_custom_table');
gr.u_pressedbutton = nowdt;
gr.u_year = gs.nowDateTime(yyyy);
gr.u_month = gs.nowDateTime(m);
gr.u_day = gs.nowDateTime(dd);
gr.insert();
But as we all know, my parameters in gs.nowDateTime() are invalid. I've searched multiple community posts and the SN wiki, but can't find a simple and clean method (as exampled above) on how to do this.
Any suggestions?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:17 AM
You can use GlideDateTime() for that.
var gdt = new GlideDateTime();
gs.log(gdt.getMonth());
GlideDateTime - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:17 AM
You can use GlideDateTime() for that.
var gdt = new GlideDateTime();
gs.log(gdt.getMonth());
GlideDateTime - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:18 AM
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 09:01 AM
By the way... I found this link extremely helpful, so hopefully someone else can benefit from it too.
http://www.snc-blog.com/2011/02/07/working-with-date-date-fields-in-imports-and-business-rules/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:44 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: GlideDateTime
Visit http://docs.servicenow.com for the latest product documentation