- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2019 04:43 AM
The GlideDateTime's addDays not working as expected. This function is not returning correct value for time
In the below example I am taking time of 90 days back from current date. However the function is returning correct value till '-78' days but not working as expected for values greater than 78.
I am wondering if this is bug in service now or am I missing any step here.
Sample Code
var toDateTime = new GlideDateTime(gs.now());
var gtime = new GlideTime();
gtime.setValue("23:59:59");
toDateTime.add(gtime);
var fromDateTime = new GlideDateTime(toDateTime.now());
fromDateTime.addDays(-90); //fromDateTime.addDays(-78); works fine till 78
gs.log("From Date Time " + fromDateTime);
gs.log("To Date Time " + toDateTime);
Output:
*** Script: From Date Time 2019-02-27 00:59:59
*** Script: To Date Time 2019-05-27 23:59:59
*** Script: Expected From Date Time 2019-02-27 23:59:59
Instead of returning 23:59:59 function is returning 00:59:59
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2019 10:12 PM
I'd recommend you to use addDaysUTC instead of addDays:
var toDateTime = new GlideDateTime(gs.now());
var gtime = new GlideTime();
gtime.setValue("23:59:59");
toDateTime.add(gtime);
var fromDateTime = new GlideDateTime(gs.now());
fromDateTime.addDaysUTC(-90); //fromDateTime.addDaysUTC(-78); works fine till 78
gs.log("From Date Time " + fromDateTime);
gs.log("To Date Time " + toDateTime);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2020 12:54 AM
i made so much logic every thing get failed other than addDaysUTC. Thanks @Oleg