IF condition to check whether "u_date" >= current date.

Aki17
Kilo Guru

I need an IF condition in UI Action script to check whether "u_date" >= current date.

*u_date is Date field type.

Please let me know how to express it in the script in the simplest way.

Best Regards,

Aki

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can use something like below in the condition field

current.u_date >= new GlideDateTime()

-Anurag

-Anurag

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

new GlideDateTime(current.u_date).getNumericValue() >= new GlideDateTime().getNumericValue()

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hitoshi Ozawa
Giga Sage
Giga Sage

Since u_date is a Date and not a DateTime field, would require to compare GlideDateTime().

"new GlideDateTime()" will return the current Date/Time and not the Date. That is, following will return something like "2022-01-26 00:10:00" instead of "2022-01-26 00:00:00". So, if the u_date is today, the if condition would return false because "new GlideDateTime()" will be greater.

var gd = new GlideDateTime();
gs.info(gd);

Taking this in account,

new GlideDateTime(current.u_date).getNumericValue() >= new GlideDateTime((new GlideDate).getValue() + ' 00:00:00').getNumericValue()

 

On second thought, it would be little bit easier to write as below:

new GlideDateTime(current.u_date + " 23:59:59").getNumericValue() >= new GlideDateTime().getNumericValue()