Jump to content

Selector date format

AAD Web Team

Recommended Posts

The selectors documentation has the example, when working with a Datetime field of:


Does this mean we can use any format compatible with PHPs strtotime function? I tried:

my_date>=5 weeks ago

…and it seemed to work. What about when using Unix timestamps? The strtotime documentation suggests you'd need:


… but we just had:


…and it seemed ok.

Anyway, given this all seems to work we can just keep doing it, but I wanted to check that this is a 'supported' way to use dates in selectors, so I know we can rely on it.

Link to comment
Share on other sites

There is a difference between selectors used with PageFinder...

$pages->find($selector), $page->children($selector), etc

...and selectors used in memory...


Any string that strtotime() understands can be used with a PageFinder selector, but with an in-memory selector you can only use timestamps. This is because when FieldtypeDatetime prepares the database query it actually passes the value through strtotime() if it isn't recognised as being an integer (timestamp) or a DateTime object. See here and here.

But FieldtypeDatetime isn't involved with in-memory selectors so in such cases if you are working with a time string you'll need to convert it to a timestamp yourself.

  • Like 3
Link to comment
Share on other sites

Thanks @Robin S – that's an excellent explanation. I didn't previously know about the difference between PageFinder and in-memory selectors. It'd probably be good if allowable date formats were explained on the selectors documentation page. (I'm not sure what the best process for suggesting documentation updates is.)

  • 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

  • Recently Browsing   0 members

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