Question

I am trying to call the order date within the admin of zen cart and add 5 days to it.

When I call the order date zen_datetime_short($orders->fields['date_purchased']); I get the following "05/27/2013 12:16:46"

I am not sure where to go, I am thinking its something like

$order_date = zen_datetime_short($orders->fields['date_purchased']);
$order_date_plus_five = $order_date+5;

echo $order_date_plus_five;

I know that is not it, but so you can understand how I am trying to use it. Any help would be greatful!

Was it helpful?

Solution

That should be pretty simple:

$order_date_plus_five = zen_datetime_short(date('Y-m-d H:i:s', strtotime($orders->fields['date_purchased']) + 5 * 24 * 3600 ));

That is, assuming your $orders->fields['date_purchased'] is in the format of Y-m-d H:i:s that is the standard format for mysql datetime format.

The main idea is that php's strtotime function generated a timestamp from a datetime string. After you generate that timestamp, you just add the number of seconds of 5 days (5 * 24 * 3600)

OTHER TIPS

Note that another way to do this would be to do it as part of the database query.

SELECT date_add(date_purchased, INTERVAL 5 DAY) AS dayplus5 FROM orders; 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top