Jump to content

Date field selector


Frank Vèssia
 Share

Recommended Posts

I have a publish date field in this format Y-m-d H:i:s

Now i want to select pages published today (of course no matter the hour)

I'm trying with

$today = strtotime(date("Y-m-d"));
$items = $pages->find("template=linkmain,publishdate*=$today,sort=-userid");

I get all pages as result, also pages with dirrefent day date...i tried also ^= with the same result...

Link to comment
Share on other sites

I have a publish date field in this format Y-m-d H:i:s

Now i want to select pages published today (of course no matter the hour)

I'm trying with

I get all pages as result, also pages with dirrefent day date...i tried also ^= with the same result...

Dates are stored as timestamp not in the format you specify. It will be formated when output. So you would have to use a timestamp to use in the selector.

For recieving page of today, you would have to create a start and end time range and use them in the selector.

<?php
$start = strtotime( date('Y-m-d') . " 00:00:00");
$end = strtotime( date('Y-m-d') . " 23:59:59");

$items = $pages->find("template=linkmain,publishdate>=$start,publishdate<=$end,sort=-userid");

haven't tested it but should work along these lines

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...