How to query date/time field?

manimozhi3
Tera Contributor

I have two date/time fields, callback start date and end date. End date is populated with 2 hours after the start time. When more than 5 incidents with same start date and end date are submitted, it should thrown an alert saying that there are already 5 incidents with the same start date and end date. And also it should clear the start date and end date.

I have created an on change client script (onchange of end date) and script include and I've passed the start and end date values to the script include. I'm unable to query the start and end dates in the script include. I tried querying the incident table with start date and end date. It is not querying the values, since both are date/time fields.

I have tried the same by creating two drop down fields for start and end time and one date field for callback date. It was working fine that time. But based on the requirement, I have changed it into two date/time fields. I have attached the scripts for reference.

Please help with your suggestions.

Thanks in advance,

Manimozhi

5 REPLIES 5

Aditya Telideva
ServiceNow Employee
ServiceNow Employee

Please use getDate method to get date alone and compare using startswith.

 

 

 

var gdt = new GlideDateTime();

 

gdt.setNumericValue(sec);

 

var checkDate = gdt.getDate();           //getting only date component

 

 

 

var gr = new GlideRecord('u_sps_availability');

 

gr.addQuery('u_date','STARTSWITH',checkDate);             //Compare using startswith

 

gr.query();

 

if(gr.next()){

 

  gs.print("yes");

 

        }

Thanks,

Aditya Telidevara