We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to compare date range in field styles

deepanshanand
Kilo Expert

Hi Experts,

I am trying to build a query that if   due date is between today and tommorow , then that record be shown with red color.

doing this in System UI ---> Field Styles

Came up with this condition

javascript: gs.dateDiff(gs.now(),current.u_due_date.getDisplayValue(), true) > 0

but not able to setup for range between today and tommorow.

Any ideas?

6 REPLIES 6

I think i am able to get the values of dates in repective fields as due date is date time field


Not sure if its going wrong in if loop



if((updDate==now)||(updDate>=now.addDaysUTC(1)))


  {


  return true;


  }


ShubhamGarg
Kilo Sage

Hi Deepansh,

dateDiff() method expects the earlier date as the first parameter and the later date as the second parameter; otherwise, the method returns the difference as a negative value and ultimately gives bad results.

Change your code like this-

javascript: gs.dateDiff(current.u_due_date.getDisplayValue(, gs.now().getDisplayValue(), true) >0;

Here, Earlier date = current.u_due_date.getDisplayValue() AND later date is gs.now().getDisplayValue()

Use getDisplayValue() to convert the strings to the expected format.

javascript: gs.dateDiff(String startDate, String endDate, Boolean numericValue);

Regards,

Shubham