- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 08:34 AM
I have tried addDays and addWeeks and addDaysLocalTime but keep getting the same incorrect answer. I'm trying to add 14 days or 2 weeks to the current date. Each attempt for 1-12-2017 gets me 1-25-2017 at 7:00 pm. It doesn't even change the time. I've seen plenty of examples on the community but they get me these results. What am I doing wrong.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 10:06 AM
Okay I misunderstood your question.
So new GlideDateTime() gets the time in the system date rather than your TZ. So it is actually giving you day 14 but in your timezone it will show as the wrong date as it's converting back to your timezone which is behind. At least that's my theory because this will work and give you what you are looking for (and will be more reliable.)
var gdt = new GlideDateTime(gs.nowDateTime());
task.start_date = gdt;
var ed = new GlideDateTime(gdt);
ed.addDays(14);
task.end_date = ed;
I ran a background script and produced the results you'd expect.
var gdt = new GlideDateTime(gs.nowDateTime());
gs.log(gdt);
var ed = new GlideDateTime(gdt);
ed.addDays(14);
gs.log(ed);
*** Script: 2017-01-12 13:04:58
*** Script: 2017-01-26 13:04:58
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2017 10:57 AM
gs.getDateTime() is the system timezone. If you want your timezone you can try:
var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime(gs.nowDateTime());
gdt.setTZ(tz);
task.start_date = gdt;
var ed = new GlideDateTime(gdt);
ed.addDays(14);
task.end_date = ed;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 11:22 AM
When you select Planned Start Date on change form, validate if Planned Start Date is after 10 days of current date. If not display an error message below the field and clear the value selected.