Forum

Thread tagged as: Question, Problem

Matching dates for news collection

Hi Guys,

I have a collection on a site used for news. In my code I have this;

        perch_collection('News', [
                'template'              =>'news/_teaser.html',
                'filter'                => 'date',
                'match'                 => 'lte',
                'value'                 => date('Y-m-d'),
                'sort'                  =>'date',
                'sort-order'            =>'DESC',
                'count'                 => 4,
                'paginate'              => true,
                'page-links'            => true,
                'page-link-style'       => all
            ]);
        }

So basically matches any articles with todays date or older and shows them, I did this so the user can add articles in the future if required(like the normal blog system). However, they have added a post today and it is not showing up? if I change the date to yesterday it is fine.
Upon outputting the two dates, the difference I see is this:

2016-03-07 00:00:00
2016-03-07

With the former being the perch one.

Any ideas how to fix/avoid this?

Thanks,
Terry

Terry Upton

Terry Upton 0 points

  • 5 years ago

If you're using the date in Perch using time="true", then you'll see the time stamp added to the date.

Change your filter value to:

 perch_collection('News', [
                'template'              =>'news/_teaser.html',
                'filter'                => 'date',
                'match'                 => 'lte',
                'value'                 => date('Y-m-d H:i:s'),
                'sort'                  =>'date',
                'sort-order'            =>'DESC',
                'count'                 => 4,
                'paginate'              => true,
                'page-links'            => true,
                'page-link-style'       => all
            ]);
        }

That'll account for the hour, minutes and seconds time stamp.

I set the time to "false" as I have the native set to "true" and using native and time as true doesn't work together.
I will try setting time to "true" and going back to the old format and seeing if this does fix it.

Thanks,

I'd give that filter value a go as it should still do the job even if Perch is storing the time and you've set it to false.

Thanks Philip. Adding the time into the filter has fixed it.