- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 01:11 PM
Hello,
I have a UI Action that is used to add days/weeks to a date. It uses a prompt. A user can enter a number. That number is passed to a script include via glideajax. In the GlideAjax, I perform the calculations. This is working, but the issue I am currently facing is for some records, the date is short by 1 date. The field I have is a GlideDate field, but I am using GlideDateTime() to handle the addition.
Please see the script below:
var entries = this.getParameter('sysparm_entry_ids');
var daysOrWeeks = this.getParameter('sysparm_entry_days_weeks');
var days = this.getParameter('sysparm_days').toString(); //returns a number
var weeks = this.getParameter('sysparm_weeks').toString(); //returns a nuber
var gr = new GlideRecord('u_compliance');
gr.addQuery('sys_id', 'IN', entries);
gr.query();
while (gr.next()) {
var currentDate = new GlideDateTime(gr.u_date);
if (daysOrWeeks == "days") {
currentDate.addDays(days);
} else if (daysOrWeeks == "weeks") {
currentDate.addWeeks(weeks);
}
gr.u_new_date = currentDate;
gr.update();
}
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 07:14 PM
Hi,
Please try using addDaysLocalTime(days) instead of addDays(days).
If that does not work then you can try using addDaysUTC(days);
Check below documentation to learn difference.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 04:27 PM
Hello mballinger,
By "short by 1 date" do you mean if the value is today (16th) it shows as 15th? If you just log out currentDate before adding days, is it correct?
GlideDateTime() gets the time in the system date rather than your TZ. So it's possibly bringing back a day short based on TZ differences.
Please mark helpful/correct if this has helped you.
Thanks,
Logan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 05:36 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2022 07:14 PM
Hi,
Please try using addDaysLocalTime(days) instead of addDays(days).
If that does not work then you can try using addDaysUTC(days);
Check below documentation to learn difference.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2025 01:04 PM
Thanks Anil!