I am attempting to get orders that were completed between two dates and the "before" and "after" criteria parameters don't seem to work. Perhaps I am using the wrong syntax? Example of how I am using them:

.after('2017-06-02 00:00:00')

It looks like I figured it out by doing this:

.dateOrdered('and', '>=' ~ startDate, '<=' ~ endDate)
  • If you want to include orders that were completed on the end date, you can do endDate|date_modify('+1 day') :)
    – carlcs
    Jun 23 '17 at 17:43
  • Does it not take the time portion into account in the parameter? For end dates, I am passing strings like "2017-06-22 23:59:59". Jun 23 '17 at 17:54
  • It does take the time into account, but only when you provide one – what you’re currently not doing! ;) '>=' ~ startDate returns a string ">=2017-06-02". You’d need to explicitly format the output using the date filter, e.g. '>=' ~ startDate|date('c') which would then output something like ">=2017-06-02T08:26+0800". If you prepend a date_modify filter you can do all sort of useful date and time calculations, see php.net/manual/en/datetime.formats.relative.php
    – carlcs
    Jun 23 '17 at 18:10
  • Sorry @Ben, I just noticed that I assumed startDate is a DateTime object in your code, which may not be the case at all.
    – carlcs
    Jun 23 '17 at 18:15
  • We are getting the expected results now so I think we're all set. Thanks for the help! Jun 23 '17 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.