Magento 2 you can get a date after 1 year period using Magento\Framework\Stdlib\DateTime\DateTime Class.
You can get easily using PHP by function date().
date(‘Y-m-d’, strtotime(‘+1 years’));
Using Magento You can get a date after 1 year by using Magento best practice way by injecting class dependency in the construct method.
<?php /** * @var \Magento\Framework\Stdlib\DateTime\DateTime */ protected $dateTime; public function __construct( Magento\Framework\Stdlib\DateTime\DateTime $dateTime, ) { $this->dateTime = $dateTime; } public function getDateAfterOneYear() { $afterOneYearDate = "+1 years"; $timeStamp = $this->dateTime->timestamp($afterOneYearDate); $expireDate = $this->dateTime->gmtDate('Y-m-d', $timeStamp); return $expireDate; }
call from template or any other function,
echo $this->getDateAfterOneYear();
Output:
2020-05-20