How to compare Date/Time field with Date field

Saranya2
Tera Contributor

Hi All,

I need to compare Date/Time field with Date field

Planned End Date - ( Date / Time ) field

End of support - (Date) field

If Planned End Date falls after End of Support then I  need to set flag value to true & need to perform some operations based on flag value. I have written below code, but in one case it is not working.

for ex : if  Planned End Date - 2022-12-21 11:30:00

                 End of support - 2022-12-21

As per the requirement, it should set the flag value to false, but it is setting to true. please find below code for reference

          
                    var mod_id = ' 1bdeb3462f271110afe33996f699b66c';

                   var hardware = true;
                    var cmdb_ci_server = new GlideRecord("cmdb_hardware_product_model");
                    cmdb_ci_server.addEncodedQuery("sys_id=" + mod_id);
                    cmdb_ci_server.query();
                    if (cmdb_ci_server.next()) {
                        var end_of_support = cmdb_ci_server.getValue('u_fedex_end_of_support');

                      var planned_end_date =cmdb_ci_server.getValue("end_date");
                        if (planned_end_date > end_of_support) {
                            hardware = 'true';
                         } else {
                            hardware = 'false';
                          }

                    }

     
   
          
           
              
                    
                
                       

1 REPLY 1

Veer
Tera Guru

 

@Saranya2  Try using 

var plannedEndDate = new GlideDateTime("2022-12-21 11:30:00")

var planedEndDate_numeric = plannedEndDate.getNumericValue();

 

var supportEndDate = new GlideDateTime("2022-12-21");

var supportEndDate_numeric = supportEndDate.getNumericValue();

 

compare supportEndDate_numeric & planedEndDate_numeric