Expand my Community achievements bar.

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
Former Community Member

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

4 Replies

Avatar

Correct answer by
Former Community Member

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 3

Thank you.

This is exactly what is needed.

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?

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----