The CreatorCon Call for Content is officially open! Get started here.

Method to reverse date to 90 days for a date field

chatsaurav19
Tera Contributor

Hi All,

 

What should be the correct method to reverse the date to 90 days? I  am trying to use this method, highlighted in bold but it isn't working.

 

var date = new GlideDate(); //Today's Date
var gdt;

var grRole = new GlideRecord('x_inpe_gbs_inf_gbs_infrastructure_roles');
grRole.addEncodedQuery('role_statusIN2,4,5,6');
grRole.query();
while (grRole.next()) {
    var projectedHireDate = grRole.getDisplayValue('projected_hire_date');
    gs.info("Old Projected Hire Date: " + projectedHireDate);
    gdt = new GlideDateTime(projectedHireDate);
    gdt.addDaysLocalTime(-90); //This method and passing -90 but isn't working
    gs.info("New Projected Hire Date: " + grRole.projected_hire_date);
}
 
Regards,
Saurabh
1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @chatsaurav19 

Replace this line.

From

gs.info("New Projected Hire Date: " + grRole.projected_hire_date);

To

gs.info("New Projected Hire Date: " + gdt.getLocalDate());

 

You will see the new date.

 

 

Cheers,

Tai Vu

View solution in original post

3 REPLIES 3

piyushsain
Tera Guru

Hi,

Is projected_hire_date DATE type of DATE and TIME type, if its date type it will not work

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Tai Vu
Kilo Patron
Kilo Patron

Hi @chatsaurav19 

Replace this line.

From

gs.info("New Projected Hire Date: " + grRole.projected_hire_date);

To

gs.info("New Projected Hire Date: " + gdt.getLocalDate());

 

You will see the new date.

 

 

Cheers,

Tai Vu

Thank you @Tai Vu . It worked!

 

Thank you @piyushsain for your help as well.