Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Adding days to a date

Avatar

Level 2

I can't get my code to work, I've read over most of the other posts regarding Adding days to a date, and I'm can't figure out why my code isn't working.

Date1 field is a Date/Time field: I want the user to select a date

Date2 field is a field that I would like a new date (Date1 + 21 days) to automatically populate.

Here is my code, it is set to run when the user exits Date1.

var Date1 = Date2Num ($, "yyyy-mm-dd")

Date2 = Num2Date (Date1 + 21, "yyyy-mm-dd")

The result is y-m-d in the Date2 field. I have tried making Date2 a text field, numeric field, and another Date/Time field, the result is always the same.

1 Accepted Solution

Avatar

Correct answer by
Level 3

I just sent it back.  I was having some issues getting it to work according to the docs and how I recommended.  Here is the code I used to get it to work properly.  I used the ISO and manipulated the date from there.

var dateNumber = IsoDate2Num($)

topmostSubform.Page1.GerminatorDate.rawValue = Num2Date(dateNumber + 21)

View solution in original post

0 Replies

Avatar

Level 3

Hello,

Make sure you are using FormCalc as both Date2Num and Num2Date are FormCalc functions and NOT js functions.

Then use:

newDateField = Num2Date(Date2Num(dateFieldWithDateNeedingToChange, "MM/DD/YYYY") + 21, "MM/DD/YYYY")


Justin

Avatar

Level 2

Both fields are FormCalc...though there is no formula in the Date2 field.

I used your formual and the result is still the same, only now the result is m/d/y.

Avatar

Level 3

Could you send me the form with a description of what you are looking for it to do?

ndjustin20 at hotmail dot com

Avatar

Correct answer by
Level 3

I just sent it back.  I was having some issues getting it to work according to the docs and how I recommended.  Here is the code I used to get it to work properly.  I used the ISO and manipulated the date from there.

var dateNumber = IsoDate2Num($)

topmostSubform.Page1.GerminatorDate.rawValue = Num2Date(dateNumber + 21)