Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
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/