Block date before tomorrow

Hi, newbie question:

I have a date picker and it defaults to today's date. The date that needs to be chosen will always be in the future.

So I either want to:

  • block ability to pick a date before tomorrow

or

  • use validation to block entry of a day that is before tomorrow.

Grateful for any help.

Hi Chris,

Welcome to the community :tada:

Here's one way you can do this:

{note}Today: {formdate: YYYY-MM-DD; name=today}
{difference=datetimediff(dates, today, "D"); trim=left}{endnote}

Future date: {formdate: YYYY-MM-DD; name=dates}

{if: difference<0}{else}{error: Pick a date in the future; block=yes}{endif}

It uses datetimediff, the if command, and the error command. If you choose a date that is in the past, or the date is today, it will show an error and block snippet insertion.

If you change the date to a date in the future, it doesn't include an error.

If you have any questions, please let me know!

1 Like

Hi Dylan, thanks so much for that. It does what I need.

However, I need to use the date format "dddd DD MMMM YYYY" so we get a full date with the dayname - like "Thursday 13 June 2024". When I use this date format in your example I get the following error:

Cannot directly convert Thursday 13 June 2024 to a date, try datetimeparse().

Any idea how I get around that?

Many thanks in advance

Chris

How's this?

{note}Today: {formdate: YYYY-MM-DD; name=today}
Future date: {formdate: YYYY-MM-DD; name=dates}
{difference=datetimediff(dates, today, "D"); trim=left}{endnote}

{=datetimeformat(dates, "dddd DD MMMM YYYY")}

{if: difference<0}{else}{error: Pick a date in the future; block=yes}{endif}

Absolutely amazing. Thank you! I am LOVING Text Blaze :grinning:

1 Like