Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Extract date parts from DateField Selected-Value

Avatar

Level 4

Hi folks,

I would like to extract the year part of my datefiedl's selected value.

For example, I would like to get 2010 from : 23/12/2010

And check if the extracted year is smaller than the current year.

How can I do it in LiveCycle(JavaScript is preferred)?

Thank you,

Yair

1 Accepted Solution

Avatar

Correct answer by
Level 10

var Input = Num2Date(Date2Num($.formattedValue, "DD.MM.YYYY"),"YYYY")

var CurrentYear = Num2Date(date(), "YYYY")

if (Input ne CurrentYear) then

     xfa.host.messageBox("Wrong Year")

endif

radzmar

http://thelivecycle.blogspot.com/

View solution in original post

4 Replies

Avatar

Level 10

You can do this with FormCalc in the exit:Event of the date field.

var Input = Num2Date(Date2Num($.formattedValue, "DD/MM/YYYY"), "YYYY")

     if (Input ne 2010) then

     xfa.host.messageBox("Wrong Year selected")

endif

Avatar

Level 4

Thank you,

How can I get the current year in code?

Yair

Avatar

Correct answer by
Level 10

var Input = Num2Date(Date2Num($.formattedValue, "DD.MM.YYYY"),"YYYY")

var CurrentYear = Num2Date(date(), "YYYY")

if (Input ne CurrentYear) then

     xfa.host.messageBox("Wrong Year")

endif

radzmar

http://thelivecycle.blogspot.com/