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

Abhinay Erra
Giga Sage

Here you go.



var gdt= new GlideDateTime();


gdt.setDisplayValue(current.<date time field name>);


gdt.getDate(); //this will give you the date


This gives me just the current system date.. Let me elaborate my case.. I am pulling a change report which has one of the columns as "Planned start date".. the value that it holds is date and time (2016-08-12 20:00:00).. what i want to do is just get the date from it and compare it against the system date and if the date matches then highlight the cell. so something like this: var gr = new GlideRecord("change_request"); if (gr.getDisplayValue('start_date') == gs.now()) { template.print(""); template.print(gr.start_date); } else { template.print(gr.start_date); }


Use this



var gdt= new GlideDateTime();


gdt.setDisplayValue(current.<field name of Planned Start Date>);


gdt.getLocalDate();


var gdt1= new GlideDateTime();


gdt1.setDisplayValue(gdt.getLocalDate());


var gdt2= new GlideDateTime();


gdt2.setDisplayValue(gs.now());


if(gdt1.compareTo(gdt2)==0){


template.print("");


template.print(gr.start_date);


}


else {


template.print(gr.start_date);


}


Doesn't work either... Also i didn't understand.. the first part.. var gdt= new GlideDateTime(); gdt.setDisplayValue(current.); gdt.getLocalDate(); why are we doing this? Thanks, Malaya