1

I am trying to show an estimated delivery date to my shipping methods, I currently have this code which is displaying the date that is it today in the format of Thursday-November-2014

<?php $currentTimestamp = Mage::getModel('core/date')->timestamp(time());
        echo 'Estimated delivery date ' ;
        echo $deliverydate = date('l-F-Y', $currentTimestamp);?>

But how can I get it to add 2 days on to the date and display that?

Thank you if you can help.

2

instead of

$currentTimestamp = Mage::getModel('core/date')->timestamp(time());

use this:

$currentTimestamp = Mage::getModel('core/date')->timestamp(time() + 2 * 24 * 60 * 60);
  • cheers i will try it in a min, could you just explain to me what *24 *60 * 60 means as i assume the 2 is 2 days – Adam Allen Nov 27 '14 at 13:08
  • 2 days * 24 hours * 60 minutes * 60 seconds, I'll give you the no math version in a minute – Richard Nov 27 '14 at 13:11
  • 2 = 2 days, 24 = hours in a day, 60 = minutes in an hour, 60 = seconds in a minute. Since time() returns a value in seconds, you need to add the number of seconds that equals to 2 days. I could have just said + 172800 but then you would have said "WHAAAT?" :) – Marius Nov 27 '14 at 13:11
  • makes sense now i didnt know it returned the values in seconds, sorry to ask for the explanination but i like to learn fixes rather than just use other peoples code. Thank you again! – Adam Allen Nov 27 '14 at 13:15
1

Mage::app()->getLocale()->date()->addDay(2);

To format it, have a look at the documentation , the one you gave in your question looks like Dayname-Monthname-FullYear which looks a little weird

0

Following code will give you the date after 2 days .

<?php 
$currentTimestamp = Mage::getModel('core/date')->timestamp(time());
echo 'Estimated delivery date ' ;
echo $deliverydate = date('l-F-Y', $currentTimestamp);
$datenew =  strtotime('2 day', $currentTimestamp);
echo date('l-F-Y',$datenew);
?>

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.