Expand my Community achievements bar.

SOLVED

Adding a year to the current date field

Avatar

Former Community Member

Hello,

Can any one please help on how to add a year to the current date field.

e.g 7/19/2011 plus a year = 7/19/2012

Thanks,

Han Dao

1 Accepted Solution

Avatar

Correct answer by
Level 10

If you had a field DateTimeField1 and wanted to display the following year in DateTimeField2, you could do the following in JavaScript;

var d1 = util.scand("yyyy-mm-dd", DateTimeField1.rawValue);
if (d1 !== null)
{
d1.setFullYear(d1.getFullYear()+1);
DateTimeField2.rawValue = util.printd("yyyy-mm-dd", d1);
}

Good luck

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

If you had a field DateTimeField1 and wanted to display the following year in DateTimeField2, you could do the following in JavaScript;

var d1 = util.scand("yyyy-mm-dd", DateTimeField1.rawValue);
if (d1 !== null)
{
d1.setFullYear(d1.getFullYear()+1);
DateTimeField2.rawValue = util.printd("yyyy-mm-dd", d1);
}

Good luck

Bruce