new GlideDateTime().getMonth not working properly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2021 11:55 PM
I need to get the current months of the 2 dates.
I am trying to use the getMonthLocalTime(), getMonthUTC() and getMonth() so as to get the current month of the date entered. If the date is larger than 12, then it is working fine and returning the month number. HOWEVER, if the date is less than 13, i.e., 1-12, then it is getting confused and returning the date of month number instead of the month number. What should I do?
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2021 12:20 AM
Hi,
Looks like the issue is due to date format. Try the Below code:
var strDate = "13/10/2020";
var dt = new GlideDateTime();
dt.setDisplayValue(strDate,"dd/MM/yyyy");
gs.print(dt.getMonthLocalTime());
ServiceNow will consider first part of date as month. If it is greater than 12 then it consider it as day and take second part as month. Set the date format based on your input so that you can force the dateformat.
Thank you,
Palani
Palani