PHP increment timestamp by one year

echo strtotime(“+1 year”);//Return timestamp, if you want to convert to general time format, you need the following function echo date(‘Y-m-d H:i:s’, strtotime(“+1 year”)); ================================================= In the same way, it can be not only +year but also day, month and day, the following code:

<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>

For a given date: First convert the string to date, then +1 year, and finally pay attention to whether it is in UTC date format

$created_time = strtotime($row->created_at);
$expire_date = date('Y-m-d H:i:s', strtotime('+1 year', $created_time));
$expire_date = DatetimeHelper::convertUTC($expire_date);

Leave a Reply

Your email address will not be published.

en_USEnglish