- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2023 03:06 PM
I created a before BR in Change, and it's able to get to whatever the next Friday from the planned start date, but the time is always set to 6 PM instead of 9 AM. How can I set it to 9 AM? Here is my script in BR,
var getDay = new GlideDateTime(current.start_date);
var t = getDay.getDayOfWeekLocalTime();
if (t == 1) {
getDay.addDaysLocalTime(5);
current.cab_date = getDay.getDisplayValue();
} else if (t == 2) {
getDay.addDaysLocalTime(4);
current.cab_date = getDay.getDisplayValue();
} else if (t == 3) {
getDay.addDaysLocalTime(3);
current.cab_date = getDay.getDisplayValue();
} else if (t == 4) {
getDay.addDaysLocalTime(2);
current.cab_date = getDay.getDisplayValue();
} else if (t == 5) {
getDay.addDaysLocalTime(1);
current.cab_date = getDay.getDisplayValue();
} else if (t == 6) {
getDay.addDaysLocalTime(7);
current.cab_date = getDay.getDisplayValue();
} else if (t == 7) {
getDay.addDaysLocalTime(6);
current.cab_date = getDay.getDisplayValue();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 08:48 AM
Hi @bbf35621 missed a line, internally time is stored in UTC. So you need one more adjustment to store date/time in UTC.
var getDay = new GlideDateTime(current.start_date);
getDay.subtract( getDay.getLocalTime() ); // subtract the time portion of dateTime
getDay.add( 9 * 60 * 60 * 1000); // add 9 hours in milliseconds
getDay.subtract(getDay.getTZOffset()); // subtract timezone offset to get UTC time
var t = getDay.getDayOfWeekLocalTime();
Also you'll notice your addDaysLocalTime is off by '1' due to this adjustment.
hope that helped
--
Bala Guthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2023 08:27 AM
I tested it in my new PDI and it showed 7 PM as the TZ is US/Eastern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2023 12:22 PM
The main reason my code wasn't working was because of the wrong variable name. I used cab_date instead of cab_date_time. I changed it and plus some hours calculation adjustments, and it worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2023 12:57 PM
I should've found it; I used the right field in my testing. 🙂
--
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2023 01:44 PM
This may function may be useful: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString