1

I am getting date by injecting this class in constructor \Magento\Framework\Stdlib\DateTime\DateTime as:

protected $date;
public function __construct(
....
\Magento\Framework\Stdlib\DateTime\DateTime $date,
....
) {
....
$this->date = $date;
....
}

and then, in class this:

$date = $this->date->gmtDate();

But how can I add or subtract month to this date for Expiration feature ?

0

You should try :

$date = $this->date->gmtDate('Y-m-d\TH:i:s\Z', strtotime('+1 month'));

0

Try this way

//Our dates
$date1 = "2013-03-01 19:12:45";
$date2 = "2014-03-01 06:37:04";

//Convert them to timestamps.
$date1Timestamp = strtotime($date1);
$date2Timestamp = strtotime($date2);

//Calculate the difference.
$difference = $date2Timestamp - $date1Timestamp;

echo $difference;

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.