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 04:27 AM
This is what I came up with:
gr_getBookings.addQuery('start_date', "<=", current.start_date).addCondition('end_date', '>=', current.start_date).addOrCondition('end_date', '>=', current.end_date).addCondition('start_date', '<=', current.end_date);
However, it doesn't appear to be working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:49 AM
Its not working because you are comparing the same dates. Can you show me screenshot of the form and then describe what exactly is the requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:57 AM
I've posted screenshots.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2019 02:27 AM
Hi Shane,
Can you try this out, tried using Encoded Query
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.addEncodedQuery('start_date<=' + current.end_date + '^start_date>=' + current.start_date + '^NQend_date<=' + current.end_date + '^end_date>=' + current.start_date);
gr_getBookings.query();
while(gr_getBookings.next()) {
//do this
}
Regards,
Kishen