How to compare 2 dates

anilkumarsharma
Giga Guru

Hello Team

i am compare 2 date using business rule but it is not working. where am I doing mistake?

 

2nd, i am running below mention code before business rule and condition have type is normal. but Business rule is not working to get the plan strat date and compare with today date. 

 

this code run through background script, but it is not comparing the date. 

currdate=new GlideDate();
gs.info(currdate);
var PlanStartdate="2023-01-24 02:30:00";
var gdt = new GlideDateTime(PlanStartdate).getDate();
gs.print(gdt);
if(currdate == gdt){
gs.info("PlanStartdate is equal to today date);
}
 
1 ACCEPTED SOLUTION

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @anilkumarsharma 

Use below below code:-

currdate=new GlideDate();
gs.info(currdate);
var PlanStartdate="2023-01-24 02:30:00";
var gdt = new GlideDateTime(PlanStartdate).getDate();
gs.print(gdt);
if(currdate.getDisplayValue() == gdt.getDisplayValue()){
gs.info("PlanStartdate is equal to today date");
}

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

2 REPLIES 2

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @anilkumarsharma 

Use below below code:-

currdate=new GlideDate();
gs.info(currdate);
var PlanStartdate="2023-01-24 02:30:00";
var gdt = new GlideDateTime(PlanStartdate).getDate();
gs.print(gdt);
if(currdate.getDisplayValue() == gdt.getDisplayValue()){
gs.info("PlanStartdate is equal to today date");
}

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Thanks Sir,