The Now Platform® Washington DC release is live. Watch now!
‎01-06-2010 10:50 AM
I need to run a query to retrieve records created within a certain date range. Been here: http://wiki.service-now.com/index.php?title=GlideRecord which implies that where operators can be passed in, but the API is short on detail.
Something like:
gr = new GlideRecord('foo'); gr.addQuery("sys_created_on", ">", "2010-01-05"); gr.query();
‎01-06-2010 12:18 PM
For date/time fields, you can add the time. e.g.,
gr.addQuery("sys_created_on", ">=", "2010-01-05 00:00:00");
gr.addQuery("sys_created_on", "<=", "2010-01-05 23:59:59");
The query to the database won't be a string comparison, but this will generate the correct SQL statement to get the right records.
Note that date/time values are stored in the database in UTC timezone (essentially GMT), so this may or may not affect what you need to query on. Testing will let you know.
‎01-06-2010 12:37 PM
Thanks for the info - I'll give this a try.
‎12-10-2020 02:09 AM
I had issue with more complex query with dates, so my solution maybe help somebody
Fields starts and ends are DateTime type
var start = current.getValue('starts');
var end = current.getValue('ends');
gr.addEncodedQuery("startsBETWEEN" + start + "@" + end + "^ORendsBETWEEN" + start + "@" + end + "^NQstarts<" + start + "^ends>" + end);