- 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 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 11:42 PM
Thank you Harshvardhan...
It works fine now

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:33 PM
for future reference, you can refer the below link for correct date format string.
https://help.talend.com/reader/3zI67zZ9kaoTVCjNoXuEyw/YHc8JcQYJ7mWCehcQRTEIw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2020 11:35 PM
put the YYYY as yyyyy (from upper case to lower case).
the upper case format gives back 'year of week', 31 december could be in week 1 of the next year.
the lower case format gives back 'current year', what you are looking for.
If my answer helped you, kindly mark it as correct and helpful.