- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2016 11:17 AM
Hi all,
Need to some help to set value received in a string field with format mm-dd-yyyy to date field(not datetime field). Can anyone help here. I am setting this value in variable of catalog item.
Thanks in advance.
Richa
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2016 12:12 PM
Here you go. use this in a server side code
var usr= new GlideRecord('sys_user');
usr.get(gs.getUserID());
var gd=new GlideDate();
gd.setDisplayValue(your date value);
current.<your date field name>=gd.getByFormat(usr.getValue('date_format'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2016 11:24 AM
Hi Richa - please try below; they both produce the same date:
gs.print(new GlideDateTime('2016-08-09').getDate()); // *** Script: 2016-08-09
gs.print(new GlideDateTime('08-09-2016').getDate()); // *** Script: 2016-08-09
EDIT: .getDate() returns GlideDate.
http://wiki.servicenow.com?title=GlideDateTime#getDate.28.29
Please feel free to connect, follow, mark helpful / answer, like, endorse.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2016 11:39 AM
Hi Richa,
First change the format of your default date. if it is YYYY-MM-DD change it to MM-DD-YYYY by going to system properties => System and there you can search for date format field and change it there.
And may be this thread may come in handy for rest
User Date Format and .setValue (date / time) inconsistencies
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2016 12:12 PM
Here you go. use this in a server side code
var usr= new GlideRecord('sys_user');
usr.get(gs.getUserID());
var gd=new GlideDate();
gd.setDisplayValue(your date value);
current.<your date field name>=gd.getByFormat(usr.getValue('date_format'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2016 02:44 AM
This works as expected,thanks Abhinay