Validate selected Date/Time with CurrentDate/Time

  • 9 January 2019
  • 8 replies
  • 83 views

Badge +11

Hello

I am trying to validate a Date|Time with the current Date|Time so that it does not allow the user to submit the request when the selected date & time is less than current date/time.

221906_pastedImage_1.png

I have tried following rules:

FromDate<Current Date

This validation works only if the FromDate is less than CurrentDate but excludes the time.
The time needs to be also validated so that a booking cannot be submited when date and time are in the past!

formatDate(FromDate, 'dd/MM/yyyy HH:mm') < formatDate(Current Date, 'dd/MM/yyyy')+ formatDate(Current Time, ' HH:mm')

This validation does not allow even if you select date/time is well in the future.

I am confused sad.png


8 replies

Userlevel 5
Badge +13

Take a look at these posts and see if one helps:

https://community.nintex.com/thread/8739

https://community.nintex.com/thread/17895-how-to-limit-date-picker-range

https://community.nintex.com/community/build-your-own/blog/2015/04/22/fun-with-forms-date-validation

https://community.nintex.com/community/build-your-own/blog/2014/10/22/how-to-complete-date-validation-using-nintex-forms-2013-validation-rules

Badge +11

Yes, I did searched on here about a solution and I was not able to solve it ...
Indeed, also used the Form Variable to generate the CurrentDate/Time and use it to validate the FromDate but no luck.

Userlevel 5
Badge +13

The below solution seems to work for me.

  1. Add a Date/Time control to the form and name it something like "TodayDateTime".
    1. Make sure that the "Default value" setting is set to "Today" and the "Date only" setting is set to "No" for this control.
    2. You can add a formatting rule to this control to hide it.
  2. Create a validation rule on the "From Date/Time" control with the following settings:
    1. Rule Type = Validation
    2. Condition = lessThan({Self}, TodayDateTime)
    3. Message = Add your own text
  3. Behavior should be that if you choose a Date/Time combination before today and click the Save button, then the control is invalid and the message is displayed.

Nintex Forms - Past Date Validation 1

Nintex Forms - Past Date Validation 2

Badge +11

Hi Eric

I guess you missed out that I require both: DATE and TIME.

Therefore, selecting "date only" makes the time selection disappear.

I already tried the LessThan function but again, it only validayes the date and ignores the time.
Ideally, I need a validation that checks if date is less then currentDate and if time is less than currentTime.

Userlevel 5
Badge +14
This validation works only if the FromDate is less than CurrentDate but excludes the time.

CurrentDate reference variable always evaluates to midnight. 

formatDate(FromDate, 'dd/MM/yyyy HH:mm') < formatDate(Current Date, 'dd/MM/yyyy')+ formatDate(Current Time, ' HH:mm')

This validation does not allow even if you select date/time is well in the future.

formatDate evaluates to string so obviously it can not compare dates correctly. at least not with used date format.

as well "+" in this case just concatenates strings and not add up two dates

you have few options how to proceed, eg

- convert date and time to comparable string formats, eg. "yyyyMMddhhmi"

- add a date control on the form and set its default value to 'Today' and let it include time as well. reference value of this control in your calculations.

note the value gets evaluated at form load and doesn't recalculate during form session. plus (for unknown reasons) it always rounds up to next full hour.

- add form variable and set its formula to:

new Date ()

(note the space between "Date" and "()" )

(note2: this will not work on responsive forms and nintex mobile)

- code your own javascript validation (will not work on responsive forms and nintex mobile)

Badge +10

@emha wrote:
This validation works only if the FromDate is less than CurrentDate but excludes the time.

 

CurrentDate reference variable always evaluates to midnight. 

 

 

formatDate(FromDate, 'dd/MM/yyyy HH:mm') < formatDate(Current Date, 'dd/MM/yyyy')+ formatDate(Current Time, ' HH:mm')

This validation does not allow even if you select date/time is well in the future.

formatDate evaluates to string so obviously it can not compare dates correctly. at least not with used date format.

as well "+" in this case just concatenates strings and not add up two dates

 

 

you have few options how to proceed, eg

 

- convert date and time to comparable string formats, eg. "yyyyMMddhhmi"

 

- add a date control on the form and set its default value to 'Today' and let it include time as well. reference value of this control in your calculations.

note the value gets evaluated at form load and doesn't recalculate during form session. plus (for unknown reasons) it always rounds up to next full hour.

 

- add form variable and set its formula to:

 

new Date ()

(note the space between "Date" and "()" )

(note2: this will not work on responsive forms and nintex mobile)

 

- code your own javascript validation (will not work on responsive forms and nintex mobile)


So what is your advice if you want to have something simple like this:

date & time input value must not be greater NOW.

 

I need this for a responsive form.

 

Cheers

mai-kel

Userlevel 5
Badge +14

So what is your advice if you want to have something simple like this:

kick the NINTEX so that they wake up and make date/time arithmetics usable in their products...

 

 

 

you see options I mentioned above, exclude those that are javascript based and doesn't work resp.  aren't supported on responsive forms, forget about 'NOW' with precision better then midnight (resp. in specific circumstances at most next full hour) and you're left with no real possibilities how to achieve what you'd like...

 

 

 

Badge +10
Thanx Emha,

I already suspected that. : (

Cheers
mai-kel

Reply