Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Automatic enter the Year in a field


Former Community Member

I have created a form with some table which contains the past 3 years. So in 2009 I have a field with 2008, a field with 2007 and one with 2006.

In 2008 I had 2007, 2006 and 2005. Now I enter this in a textfield and changes this every year. But now I would like to do this automaticaly.

I can get the current date in a time field but then I have the following format YYYY-MM-DD HH-MM but I only need the YYYY. Once I have this I think I can use calculate to distract the rawvalue with 1, 2 and 3 so I get for 2009: 2009-1=2008 , 2009-2=2007 and 2009-3=2006.
1 Reply


Level 4
var currentTime = new Date();

var year = currentTime.getFullYear();

This gives you a variable "year" which has the current year in YYYY format.