Get order between two status

Asked by At

I have a problem in getting the sum of time taken between an order

I can able the get the created time by the following code:

$collection = Mage::getResourceModel('sales/order_status_history_collection')
    ->addAttributeToSelect('created_at')
    ->addAttributeToFilter('status', array('eq'=>'complete'))
    ->load()

is there a way to get the sum of time taken between two status like sum(OrderInvoiced+OrderShipped) ?

Any help would be appreciated.

1 Answers

0
Rakesh Kumar Jakhar On

You can use the direct SQL queries method to get the time difference between invoice and shipment created.

Magento Direct SQL Queries

Invoice is saved under sales_flat_invoice and shipment are saved under sales_flat_shipment. There are 2 dates for each created_at and updated_at in both tables.

Here is the SQL query to get the difference between invoice and shipment based on created_at column

SELECT TIMEDIFF(ss.created_at,si.created_at) As TimeTaken 
FROM `sales_flat_invoice` si 
JOIN `sales_flat_shipment` ss 
ON si.order_id=ss.order_id 
WHERE si.order_id=1

To get the time difference for all the order just remove WHERE si.order_id=1 from the above query.