4

I need to save to db current date & "current date + 7days" values. For this I'm using following function. But how to add 7 days to this.

 Mage::getModel('core/date')->date('Y-m-d H:i:s');

Thanks in advance.

Update:

$res = Mage::getModel('rad_inventorypieces/reserve');
$date = new Zend_Date(Mage::getModel('core/date')->timestamp());
$res->setCreatedDate($date);
$date->addDay('7');
$res->setExpiryDate($date);
11

In OOP style:

$date = new Zend_Date(Mage::getModel('core/date')->timestamp());
$date->addDay('7');
$date->toString('YYYY-MM-dd HH:mm:ss'); //Returns representation of date 
| improve this answer | |
  • its giving result fine when echoing..but when i saving to db its saving like this 2014-11-07 02:58:41 – sivakumar Oct 24 '14 at 10:00
  • when echo..Oct 24, 2014 2:48:44 AM,Oct 31, 2014 2:48:44 AM fine. – sivakumar Oct 24 '14 at 10:04
  • could post the lines please? – Detzler Oct 24 '14 at 10:08
  • Yep go with this one, cleaner solution than mine. – Jonathan Hussey Oct 24 '14 at 10:10
  • 1
    it must be setCreatedDate($date->toString('Y-M-d H:m:s')) – Detzler Oct 24 '14 at 10:25
1

Try this :

$date = Mage::getModel('core/date')->date('Y-m-d h:i:s');
echo $date . '<br>';

$nextDate =  Mage::getModel('core/date')->date('Y-m-d h:i:s', strtotime($date." +7 days"));

echo $nextDate . '<br>';

$res=Mage::getModel('rad_inventorypieces/reserve');
$res->setExpiryDate($nextDate);
| improve this answer | |
0

You can use the underlying Zend methods:

$now = new Zend_Date(Mage::getModel('core/date')->timestamp(), Zend_Date::TIMESTAMP);
$now->set(strtotime('+7 days', $now->toString(Zend_Date::TIMESTAMP)), Zend_Date::TIMESTAMP);
$now = $estimate->toString(Zend_Date::TIMESTAMP);

This will give you an epoch time output of 7 days from the time the code runs, you can use this in date() or wherever you need to.

| improve this answer | |
  • Call to a member function toString() on a non-object – sivakumar Oct 24 '14 at 9:45
  • I can assure you the above works, where exactly are you running the code? – Jonathan Hussey Oct 24 '14 at 10:01
  • in observer file.place order after event – sivakumar Oct 24 '14 at 10:20
0

here's mine

$Date = Mage::getModel('core/date')->date('Y-m-d H:i:s');
echo date('Y-m-d H:i:s', strtotime($Date. ' + 1 days'));
echo date('Y-m-d H:i:s', strtotime($Date. ' + 7 days'));
| improve this answer | |

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.