Skip Navigation

[Resolved] Dates in Views filters

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

Problem: I have two custom fields for start date and end date. I would like to create a View that displays posts where the start date has already passed and the end date has not already occurred.

Solution: In this case, I would use a combination of start date less than or equal to TODAY, and end date less than FUTURE_DAY(1). I would also be sure to use data type "number" instead of "DATE" in the query filter.

Relevant Documentation:
https://toolset.com/documentation/user-guides/date-filters/

This support ticket is created 5 years, 1 month 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 6 replies, has 2 voices.

Last updated by nicolaS-3 5 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1373885

Hi
I am setting up a View filter for selecting only (custom) posts where "start_date >= TODAY and end_date =< TODAY". No posts are displayed.
For in WP Settings I have selected the European date format dd/mm/yyyy I am wondering how TODAY is considered in Toolset. I coudn't find any date settings in Toolset. Do you have a clue why the filter doesn't work ?
Thanks
Nicola

#1373933

Hi, Toolset Types date fields are stored in the database as Unix timestamps, so if start_date and end_date are coming from Types fields then the date format you have chosen for WordPress shouldn't matter. However, the filter terms you provided seem invalid.
start >= TODAY (this means the event starts in the future)
end <= TODAY (this means the event ends in the past)

So you're looking for events that start in the future AND end in the past? That seems contradictory, unless I'm misunderstanding something.

Where are the start date and end date values coming from - are they created by Types custom fields, or by another 3rd party plugin?

#1373949

Hi Christian,
Actually what I want to achieve is to show a post only if today's date falls between start_end and end_date (both Types custom fields). This means that the post will be visible only after the start_date and will not be displayed after the end_date. The filter window doesn't seem to allow building such a filter, any clue ?
thanks

#1373953
Screen Shot 2019-10-31 at 9.48.10 AM.png

Okay I understand, thanks for the clarification. In this case, I would use a combination of start date less than or equal to TODAY, and end date less than FUTURE_DAY(1). FUTURE_DAY(1) is essentially midnight tonight/tomorrow morning, so you have a timespan from midnight last night/this morning to midnight tonight/tomrorow morning. Take a look at the screenshot here for an example.

#1374003
date.png

Hi Christian,
I understand the trick and tried it but it doesn't work. I noticed that even the simple start_date <= (or >=) TODAY doesn't work.
All my test posts have a start date of Oct 28th, today is Oct 31st, they shoud be retrieved .... Please check.
Thanks

#1374015

I see you have selected data type "DATE". You should select "number" instead. The Unix timestamp format in the database is different from DATE, and is stored as a simple number.

#1374161

My issue is resolved now. Thank you! that's the trick !