
- 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
‎09-20-2017 04:30 AM
The link to docs.servicenow.com is laughable.. no offense. Wiki is far more helpful. docs.sn needs a major overhaul with usability and is severely deprived of meaningful content. I'm also a little surprised you would necro a 2-year old answered question to post this silliness.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2017 06:28 AM
Just doing what I'm told to do

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2017 06:31 AM
Hey, don't take it personally I'm just being feisty today! ::pokes::