- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 10:52 PM
The below script is not working as expected.
The variable longDateTime should print value as "December 31, 2019" but it is printing as "December 31, 2020".
var current = new GlideRecord('proc_po');
current.addEncodedQuery('u_amat_poSTARTSWITH4400475274');
current.query();
if(current.next()){
var gDateTime = new GlideDateTime(current.po_date.getDisplayValue());
var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM dd, YYYY");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
}
Need help to fix this.
Thanks,
Francis Xavier K.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:31 PM
ohk got the issue. try now , i have tested it.
var a = '2019-12-31 08:00:00';
var gDateTime = new GlideDateTime(a);
var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM d, yyyy");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
If my answer helped you, kindly mark it as correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 10:59 PM
Hi Francis,
can you print the gDateTime value?
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
03-12-2020 11:10 PM
Hi Ankur,
below is the output we are getting for gDateTime.
2019-12-31 13:30:00

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:12 PM
try now.
var current = new GlideRecord('proc_po');
current.addEncodedQuery('u_amat_poSTARTSWITH4400475274');
current.query();
if(current.next()){
var gDateTime = new GlideDateTime(current.po_date);
gDateTime.getDisplayValueInternal();
var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM dd, YYYY");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:29 PM
It gives the same result.
Check the below simplified script:
var a = '2019-12-31 08:00:00';
var gDateTime = new GlideDateTime(a);
var gDate = gDateTime.getDate();
gs.print(gDate); // prints - 2019-12-31 - correct value
var longDateTime = gDate.getByFormat("MMMM dd, YYYY");
gs.print(longDateTime); // prints - December 31, 2020 - wrong year
which gives the same result.