How to compare current datetime to a datetime field on form?


Badge +4

I need to compare the current datetime to a datetime field on my Nintex form for validation purposes.  I'd like to ensure date and time entered in the form has already passed and does not occur in the future.

I am encountering one issue though, which does not make this as straightforward as I'd initially thought.  The Current Date field returns the correct date, but always with 12:00 AM as the time.  The Current Time field just provides the time, for example 12:28 PM.

Is there a built in way to access the full, current datetime with the correct time?  If not, what would be the simplest way to format the Current Date and Time reference fields so that they can be compared to another datetime field using a Boolean function (in this case, greater than or less than).

Thanks!


3 replies

Badge +9

Hi

I have the following solution. You can build a date object with current date and current time which You can use in a validation rule.

I used two Form variables:

The formula:

formatDate(Current Date, 'ddMMyyyy')+ formatDate(Current Time, 'HHmm;')

Result is e.g.: 050520151552;

';' in formating string avoids supressing the leading zero in result string.

Now You can build the date object with formula:

date(subString(curr_date_time_str,0,2), subString(curr_date_time_str,2,2),subString(curr_date_time_str,4,4),subString(curr_date_time_str,8,2),subString(curr_date_time_str,10,2))

This date object can be used in validation rule to test a Date/Time control.

Kind regards

Manfred

Badge +4

Thanks Manfred, that looks like it should do the trick.  I will try implementing this when I have some time and will update with my results.

Badge +4

That did it!  Thanks!

Reply