Current Date with addDaysLocalTime not showing correctly

matthew_hughes
Kilo Sage

On a form, I'm wanting the Next AMA Due Date field to be updated by 1 year from the current date. The field is being triggered by a flow. The Next AMA Due Date is a Date field. Within my flow, I'm using the current code:

 

 
var currentDate = new GlideDateTime();

currentDate.addDaysLocalTime(365);

return currentDate;
 
However, when the code runs, what I've noticed is that it's flipping the month and day fields around.  In the below example, the Next AMA due date field should be set to 05-07-2025 instead of 07-05-2025

matthew_hughes_0-1720169012029.png

 

The Last scoping AMA completed date field is showing correctly as that just gets the current date by using gs.now(). Does anyone know what's going wrong with my code and what I can do to get the format correct?

 

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Try this

var gdt = new GlideDateTime();
gdt.addYearsUTC(1);
gs.info(gdt.getDisplayValue());
-Anurag

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Try this

var gdt = new GlideDateTime();
gdt.addYearsUTC(1);
gs.info(gdt.getDisplayValue());
-Anurag

Hi @matthew_hughes  just checking if this worked or not?

-Anurag

Hi @Anurag Tripathi  Thanks very much. That worked

Satishkumar B
Giga Sage
Giga Sage

Hi @matthew_hughes 

 

 

var currentDate = new GlideDateTime();

// Add 1 year to the current date
currentDate.addYearsLocalTime(1);

// Format the date to ensure correct display and storage
var formattedDate = currentDate.getLocalDate().getDisplayValue();

gs.info('Next AMA Due Date: ' + formattedDate);

 

 

 

--------------------------------------------------------------------------------------------------------------------
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.