- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 09:18 PM
the expected output is 2005-01-31 but I'm getting 0036-06-27. how to resolve this?
Solved! Go to Solution.
- Labels:
-
HR Service Delivery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 11:17 PM
Hi Kukunooru,
Use the following in background script;
var gd = new GlideDateTime();
gd.setValue('31-03-2005');
gs.print(gd.getDate());
*** Script: 2005-03-31
Hopefully, this will resolve your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 01:10 AM
actually there seems to be some issue with setValue.
while it worked for the above date, if we try the same with date value less than 12, it is writing YYYY-dd-MM instead of YYYY-MM-dd.
example -
var gd = new GlideDateTime();
gd.setValue('03-01-2008');
gs.info(gd);
var start = gd.getDate();
it is giving 2008-03-01 00:00:00 instead of 2008-01-03.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 01:41 AM
Check my above response
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 01:50 AM
thanks for taking time to debug Ankur. Now this is almost giving me correct answer when date selected is above 12. and incorrect answer when date is below 12 (because setValue not setting proper value)
getting correct
getting incorrect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 03:27 AM
Hi Ankur! it is working now.
instead of setValue(), I have used setDisplayValue()
Thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2022 01:52 AM