Jump to content
e0f

modified, created field problem

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!

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...