cancel
Showing results for 
Search instead for 
Did you mean: 
bimi82
Nintex Newbie

Validate selected Date/Time with CurrentDate/Time

Jump to solution

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.

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

Labels: (3)
0 Kudos
Reply
8 Replies
bimi82
Nintex Newbie

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution

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.

0 Kudos
Reply
Nintex Employee
Nintex Employee

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution

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

0 Kudos
Reply
bimi82
Nintex Newbie

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution

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.

0 Kudos
Reply
Automation Master
Automation Master

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution
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)

View solution in original post

Reply
mai-kel
Nintex Newbie

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution

@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

0 Kudos
Reply
Automation Master
Automation Master

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution

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...

 

 

 

0 Kudos
Reply
mai-kel
Nintex Newbie

Re: Validate selected Date/Time with CurrentDate/Time

Jump to solution
Thanx Emha,

I already suspected that. : (

Cheers
mai-kel
0 Kudos
Reply