Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

compare date fields

Avatar

Level 3

i have two date fields in different subforms.

the first must be older then the current date

and the second must be newer than the first date.

i tried to create a javascript to validate the fields, but i don't know how to do this

anyone?

1 Accepted Solution

Avatar

Correct answer by
Level 10

The attached contains currentDate as a calculated field.

// form1.page1.subform1.currentDate::ready:layout - (FormCalc, client)

$.rawValue = Concat(Num2Date(Date(), "MM/DD/YYYY"))

The exit events for the two date fields are as follows:

// form1.page1.subform1.firstDate::exit - (FormCalc, client)

var currentDateNum = Date2Num(form1.page1.subform1.currentDate,"MM/DD/YYYY")

var date1Num = Date2Num($.rawValue,"YYYY-MM-DD")

if (date1Num <= currentDateNum) then

  xfa.host.messageBox("The first date must be after the current date.")

endif

// form1.page1.subform1.secondDate::exit - (FormCalc, client)
var date1Num = Date2Num(form1.page1.subform1.firstDate,"YYYY-MM-DD")
var date2Num = Date2Num($.rawValue,"YYYY-MM-DD")
if (date2Num <= date1Num) then
  xfa.host.messageBox("The second date must be after the second date.")
endif
    
Is that what you are after?
    
Steve

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

The attached contains currentDate as a calculated field.

// form1.page1.subform1.currentDate::ready:layout - (FormCalc, client)

$.rawValue = Concat(Num2Date(Date(), "MM/DD/YYYY"))

The exit events for the two date fields are as follows:

// form1.page1.subform1.firstDate::exit - (FormCalc, client)

var currentDateNum = Date2Num(form1.page1.subform1.currentDate,"MM/DD/YYYY")

var date1Num = Date2Num($.rawValue,"YYYY-MM-DD")

if (date1Num <= currentDateNum) then

  xfa.host.messageBox("The first date must be after the current date.")

endif

// form1.page1.subform1.secondDate::exit - (FormCalc, client)
var date1Num = Date2Num(form1.page1.subform1.firstDate,"YYYY-MM-DD")
var date2Num = Date2Num($.rawValue,"YYYY-MM-DD")
if (date2Num <= date1Num) then
  xfa.host.messageBox("The second date must be after the second date.")
endif
    
Is that what you are after?
    
Steve

Avatar

Level 2

How would you go about making the first date user entered (possibly the current date) and formatting it all to a MM/DD/YY?

Avatar

Level 2

This is in Formcalc

How would you go about this same operation in Java?