Show an element until a certain date?

Hi!

I am struggling with the condition to show a section only until a certain date. I figure it should be the daytime condition, but what to put in there?

I have tried to set Current date is before a certain date, but this is not working. Maybe the formatting is off, but then again, how to know which formatting is right? The one I use is set in the WP settings.

image
image

I think there should be a date picker in the conditions, with time included. So people can easily put certain date/time with ease.

Thanks!

Hi @Misho,

Thanks for your valuable suggestion, but the Conditions are made in such a generalized way, where any conditional logic can be entered. There is no such option to detected the type of logic, and that is why the input option is made and allowed users to add their own set of conditions or the value to compare.

Thanks for understanding.

Hi, I was just writing the new problem with this. I got the condition working, but run into something that looks like a bug:

The section should be showing until February 20th. My default WP format is 20/02/2021.

This is the problem:

At previous and today’s date, the section is hidden. That is ok.
image

Until 4 days from now, the section is visible.
That is ok as well. It is supposed to be shown all the way until February 20th.
image

However, as soon as February 13th is set, which is 5 days from now, the section gets hidden.
image

So If I set 20/02/2021 as the date to hide the section, it seems like it will not be shown up until 5 days before the set date, which makes no sense.

Thanks!

Hi @Misho,

I’ve checked this out and I think I know what’s going on here. First off, yes, we should put a date picker in there. I’ll add that to the list.

The expression code is very simple. We take dates $a and $b and parse dynamic content to get two string date representations. Then we pass them to PHP’s strtotime function which provides a unix timestamp for each that we can simply compare.

strtotime( $a ) > strtotime( $b );

The strtotime function makes assumptions about the format. If you use slashes it assumes an American Month/Day/Year date and if you use hyphens it assumes a European Day-Month-Year date.

That’s probably what’s going on with your condition. When we add the date picker it will return a UTC formatted timestamp which is explicit and won’t make strtotime have to guess.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.