How to compare dates in a GlideRecord query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 03:14 AM
Hi, I'm trying to compare Date fields (not date/time, just date fields). I want it to only get me records where the start dates are after the current end date, or where the end dates are after the current start date. Basically, to ensure no other bookings occur on these dates. Code below:
var gr_getBookings = new GlideRecord('x_210272_insta_ava_instance_booking');
gr_getBookings.addQuery('name_of_instance', current.name_of_instance);
//Verify there are no bookings where the start date is before the current end date, or where the end date is after the current start date.
gr_getBookings.addQuery('start_date', "<=", current.end_date).addOrCondition('end_date', '>=', current.start_date);
gr_getBookings.query();
while(gr_getBookings.next()) {
//do this
}
However, the while loop always runs, even if there are no records within the date range?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 03:21 AM
Put this in gr.addEncodedQuery('start_date<=javascript:gs.daysAgoEnd(0)^end_date>=javascript:gs.daysAgoStart(0)')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 03:33 AM
The only issue is the current.start_date and current.end_date are values the user has input, so they'll be different every time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 03:36 AM
yes, this is the field name, value will be picked up from whatever user has entered in these fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:04 AM
The user will enter a start date, e.g. Sept 10 2018, they will also enter an end date, e.g. Sept 21 2018.
I want to then compare this start and end date to all the other records, ensuring that none of them overlap, i.e. this isn't already booked for those dates.