How to compare dates in a GlideRecord query

Shane18
Kilo Expert

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?

10 REPLIES 10

Soumita3
Tera Expert

Hi Shane,

 

Even if we use GlideRecord query, GlideDaTeTime() query needs to be used to get the date and time.

 

Please mark the answer as correct/helpful if it suffice your query.

 

Thanks.
Soumita.