Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Date comparison issue

sainath3
Giga Guru

Hi All,

 

Please provide you inputs for below issue.

 

Requirement:

In our custom table we have two fields, Start Date & End Date, every time if any new record is created, it should check with existing records and make sure to add start date before the start date of existing records.

I have written OnChange client script & Script includes.

but if I enter the date as 11-12-2025.//Dec 11th

Expected output is: Please select before: 12-11-2025

Actual output: no alert it is accepting.

In my RCA:

while comparing it is considering start date as mm-dd-yyyy.

In existing there are multiple records are created.

ex: Here End user changed their date format to dd-mm-yyyy.

Fal IDStart DateEnd Date
12312-11-202531-12-2025

Sample code:

ar sdate="11-12-2025";
var gdt = new GlideDateTime(sdate);
//var dateOnly = gdt.getLocalDate();
var dateOnly=gdt.getDate();
gs.print(dateOnly);
Output: 2025-11-12//Nov 12th
0 REPLIES 0