Jump to content

modified, created field problem


e0f
 Share

Recommended Posts

Hi all guys,

I'm in search to show pages created between a range.

That's my code:
$pages->find("template=test, id>1, sort=myFieldName, sort=-created, status=unpublished, (created>=2019-06-08, created<=2019-06-10");

The output is an array of pages with creation date between 8 June to 9 June.
The correct output would be from 8 June to 10 June.

How can I fix this?
Thanks for support!

Link to comment
Share on other sites

Sorry this is my code:

$pages->find("template=test, id>1, sort=myFieldName, sort=-created, status=unpublished, (created>=2019-06-08, created<=2019-06-10)");

Edited by e0f
Link to comment
Share on other sites

Welcome to the forums @e0f ?

When you use a datetime string (e.g. 2019-06-08) in a $pages->find() selector, the string gets converted to a timestamp behind the scenes via strtotime(). And if you only supply a date without any hours/minutes/seconds to strtotime() then 00:00:00 (midnight) is assumed.

This means that in your selector you are actually searching for pages created between 2019-06-08 00:00:00 and 2019-06-10 00:00:00, so you will not find any events created after 00:00:00 on 10 June.

So you can fix this by including a time in the second datetime string:

$result = $pages->find("template=test, id>1, sort=myFieldName, sort=-created, status=unpublished, created>='2019-06-08', created<='2019-06-10 23:59:59'");

 

21 hours ago, e0f said:

(created>=2019-06-08, created<=2019-06-10)

Also, you don't need parentheses around this portion of the selector.

  • Like 1
  • Thanks 1
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...