Skip Navigation

[Resolved] Conditional Today() when the custom date field contains time also?

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to create a conditional that tests the value of a custom date field. If the date is today - the current date - then I would like to display some content. However, testing the value against TODAY() does not seem to work.

Solution: You must create a conditional that tests if the date value is between the end of yesterday - TODAY() - and the beginning of tomorrow - FUTURE_DAY(1).

[wpv-conditional if="( $(wpcf-birthdate) gte 'TODAY()' ) AND ( $(wpcf-birthdate) lt 'FUTURE_DAY(1)' )"]
Happy Birthday! It's today!
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by bobA-2 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1166835

I want to show the text Today based on a custom date field. The issue is that the date field also includes time information so
[wpv-conditional if="( $(wpcf-event-date) eq 'TODAY()' )"] will not return results.

So how can I do it?

#1167262

Hi, TODAY() returns a Unix timestamp from 0:00 (12:00 am) on today's date, UTC +0. If your event start date is anything other than that exact timestamp, this conditional will show no results. Instead, you should probably test if the custom field value is less than DAYS_FROM_NOW(1), and greater than or equal to TODAY(). That will cover all timestamps between the end of yesterday and the beginning of tomorrow.

[wpv-conditional if="( $(wpcf-birthdate) gte 'TODAY()' ) AND ( $(wpcf-birthdate) lt 'DAYS_FROM_NOW(1)' )"]
Happy Birthday! It's today!
[/wpv-conditional]
#1167496

Thanks for your reply. If I turn debug on I can see that DAYS_FROM_NOW(1) is not showing as a number?

####################
DEBUG INFORMATION
####################
--------------------
ORIGINAL EXPRESSION: ( $(WPCF-PROGRAM-TIDSPUNKT) >= 'TODAY()' ) AND ( $(WPCF-PROGRAM-TIDSPUNKT) < 'DAYS_FROM_NOW(1)' )
--------------------
AFTER MATCHING 1 NUMERIC STRINGS INTO REAL NUMBERS: ( $(WPCF-PROGRAM-TIDSPUNKT) >= 1545004800 ) AND ( $(WPCF-PROGRAM-TIDSPUNKT) < 'DAYS_FROM_NOW(1)' )
	MATCHED '1545004800' TO 1545004800
--------------------
CONVERTED EXPRESSION: ( 1545165000 >= 1545004800 ) AND ( 1545165000 < 'DAYS_FROM_NOW(1)' )
--------------------
#1167898

Let's try FUTURE_DAY(1) instead:

[wpv-conditional if="( $(wpcf-birthdate) gte 'TODAY()' ) AND ( $(wpcf-birthdate) lt 'FUTURE_DAY(1)' )"]
Happy Birthday! It's today!
[/wpv-conditional]
#1167916

My issue is resolved now. Thank you!