- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2015 10:22 AM
I'm looking to create an array of dates based on the range of two date variables within a requested item. Ultimately, once I retrieve the range of dates, I'll need to see if any of these dates fall within a separate range of dates. If so, I'll return a record. This is part of a defined relationship to show records within a 2 week period where date ranges captured within the RITM fall within this 2 week period.
My original thought was to grab both date variables, get the difference in seconds, figure out the days between them, then loop through and add days to the start date til the end date is reached. Is there a better way? I haven't really ran this just a rough idea of my thoughts.
var start;
var end;
var dates;
var secs;
var days;
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', {sys_id of item});
ritm.query();
while (ritm.next()){
start = ritm.variables.start_date1;
end = ritm.variables.end_date1;
secs = gs.dateDiff(start1, end1, true);
days = Math.floor(secs / 86400);
for (x=0; x < days; x++){
dates.push(start.addDays(x));
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2015 02:48 PM
This is what I ended up with.. notice the addDaysUTC which is required in Fuji within a scoped app (addDays no longer works). Function returns all dates between 2 dates (including start and end date).
getDateRange: function(start,end){
var dates = [];
while ((start.getNumericValue() <= end.getNumericValue())){
dates.push(start.getLocalDate());
start.addDaysUTC(1);
}
return dates;
},
Updated: I found out later that getLocalDate() is needed otherwise it will use the 'system' timezone (yes system, not UTC). If not used, then any dates provided that are near the end of the day will end up using the next day or vice versa.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2015 02:48 PM
This is what I ended up with.. notice the addDaysUTC which is required in Fuji within a scoped app (addDays no longer works). Function returns all dates between 2 dates (including start and end date).
getDateRange: function(start,end){
var dates = [];
while ((start.getNumericValue() <= end.getNumericValue())){
dates.push(start.getLocalDate());
start.addDaysUTC(1);
}
return dates;
},
Updated: I found out later that getLocalDate() is needed otherwise it will use the 'system' timezone (yes system, not UTC). If not used, then any dates provided that are near the end of the day will end up using the next day or vice versa.