compare just the date for a planned change with current date

Malaya
Giga Expert

I am pulling in change records for the week using notification script... what i want to do is, compare the planned start date (just the date not time) to current date and highlight the cell... Issue i am running is that, planned start date field has both date and time but i want just the date to be compared.. Thanks, Malaya

1 ACCEPTED SOLUTION

Thank Jake..



Your piece of code helped me figure out the right piece so thank you for that...



This is what worked for me:



var gdt= new GlideDateTime(gr.getDisplayValue('start_date'));


var startDate = gdt.getLocalDate();



var gdt1= new GlideDateTime(gs.nowDateTime());


var compareDate = gdt1.getLocalDate();



  if(compareDate.compareTo(startDate)==0){


  template.print("<td bgcolor=#cde4f4>");


  template.print(gr.getDisplayValue('start_date'));


  }


  else {


  template.print("<td>");


  template.print(gr.getDisplayValue('start_date'));


  }



Thanks everyone for your inputs..



Thanks,


Malaya


View solution in original post

11 REPLIES 11

Thank Jake..



Your piece of code helped me figure out the right piece so thank you for that...



This is what worked for me:



var gdt= new GlideDateTime(gr.getDisplayValue('start_date'));


var startDate = gdt.getLocalDate();



var gdt1= new GlideDateTime(gs.nowDateTime());


var compareDate = gdt1.getLocalDate();



  if(compareDate.compareTo(startDate)==0){


  template.print("<td bgcolor=#cde4f4>");


  template.print(gr.getDisplayValue('start_date'));


  }


  else {


  template.print("<td>");


  template.print(gr.getDisplayValue('start_date'));


  }



Thanks everyone for your inputs..



Thanks,


Malaya


jake_mckenna
ServiceNow Employee
ServiceNow Employee

You should check out the GlideDateTime - ServiceNow Wiki and look at functions such as getLocalDate(). That will output only the date and allow you to compare in some fashion. At that point i would maybe say take on the compareTo() also.