Recently had to add date selectors into a report module I was writing for Magento Enterprise, came across an issue with the date selectors and how they are formatted. Causing the data to not actually sit between these dates.

I ended up with the following code to pull out all completed orders between two dates.

The $fromDate and $toDate gets passed through strtotime() function to convert them into a timestamp.

Let’s break down this code

We firstly started of by formatting our from and to dates with the date command in the following format YYYY-MM-DD HH:MM:SS

We then call in the sales/order collection and add the created_at attribute.

We then finally add in the attribute to make sure that the order is complete, you don’t need this and can alternatively check for other statuses of orders.

The main part is to remember to format your dates in the correct format.

Dave Macaulay
Dave Macaulay
I'm an enthusiastic, slightly eccentric Magento developer who bores with the idea of another basic brief.
  • Nice!

  • Ketaki

    Very Nicely explained .

    • Thank you!
      Considering this should really be so simple I thought it would be a good idea to document it for others benefit.

  • jaimin dave

    yes very helpful for me