Expand my Community achievements bar.

Need help with Date Claculation

Avatar

Former Community Member
Hey All,



I have done some searching and found you can have a date field auto fill the current date/time. but is it possible to have it auto fill a future date, say 15 months from the current date?



thanx in advance.



Kelly.
2 Replies

Avatar

Level 7
You have to use JavaScript to use the methods to strip out the year, month and date values from the date time object. Using a text field use the following calculation:



var oToday = new Date() // get today's date object

// create a date object using today's date to the fullYear of today, today's month + 15 months, and today's date using the "Date()" method with the year, month and date parameters

var oFutureDate = Date(oToday.getYear(), oToday.getMonth() + 15, oToday.getDate());

// format future date as "mm/dd/yyyy" using the "util.printd()" method

$.rawValue = util.printd("mm/dd/yyyy", oFutureDate);

Avatar

Former Community Member
Thanx for the reply Geo, but I am having trouble getting this to work. i am a total newbie, so I am fumbling around.



Using your script the field output is jumbled, it seems to show as: 9088/-7860/31308



here is how I used it:



var oToday = new Date(Date1.formattedValue);

var oFutureDate = Date(oToday.getYear(), oToday.getMonth() + 15, oToday.getDate());

Date2.rawValue = util.printd("mm/dd/yyyy", oFutureDate);



So far i got this script to sort of work :



(Date1)

Num2Date(Date(), "MM/DD/YYYY")



(Date2)

var Now = new Date(Date1.formattedValue);

Date2.rawValue = (Now.getMonth()+4) + "/" + Now.getDate() + "/" + (Now.getYear()+1901);



But once the date1 value is > 8 (Aug) the date does not roll over to a new year, it just keeps going up. eg, if Date1 is 9/1/07 Date2 will read 13/1/07 instead of 1/1/08.



Can anyone help with this?