jr204
Apprentice

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

Jump to solution

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!

0 Kudos
Reply
3 Replies
mlauer
Collaborator

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

Jump to solution

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

';' 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

Reply
jr204
Apprentice

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

Jump to solution

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.

0 Kudos
Reply
jr204
Apprentice

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

Jump to solution

That did it!  Thanks!

0 Kudos
Reply