Forum

Thread tagged as: Question, Problem

Filtering from a date field

Hi,

I have a very simple gig listings page on a client site which comprises of just "Gig Date" - and "Artist Name(s)" I'm using standard Perch install, latest version, not Runway.

I'm wanting to have the listings only show gigs that are either today or in future and hide/filer out automatically any that have passed by, i.e. yesterday back.

I'm guessing I need to be using a combination of perch custom content and filter options, but just unsure of the exact syntax for this.

Many thanks, Greg

Greg Wallace

Greg Wallace 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Sure:

perch_content_custom('Gigs', [
    'filter' => 'date',
    'match' => 'gte',
    'value' => date('Y-m-d H:i:s'),
]);

Thanks Drew,

That's working thanks, but it is excluding gigs happening today. I'm guessing that's because the date stamp from using the date field in admin by default would be today's date with time at 00:00:00

What would be the way around the filter / formatting being able to show results including today? Thanks again, Greg

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think it should be:

'value' => date('Y-m-d 00:00:00'),

Hi Drew, thanks for the quick support response again, however that returned the same result, but this syntax is working for me to show a gig today and in future but not in the past:

'value' => date('Y-m-d 00:00:00',strtotime('yesterday'))

Many thanks again.