使用php保存的数据添加+1年


Add +1 year with data already saved using php

我有这样的日期格式的数据库:28 - 04 - 2015

如何用php添加数据+1年?

知道吗?

非常感谢!

echo date('d - m - Y', strtotime('+1 years', strtotime(str_replace(" ", "",$DateFromDB))));

编辑:抱歉格式错误

工作示例:
http://sandbox.onlinephpfunctions.com/code/148e670733af48fdde6fc37884550744defb6eca

您可以使用INTERVAL 更新数据库

UPDATE table SET date = DATE_ADD(date, INTERVAL 1 YEAR) 

假设您将日期值保存在名为$date:的变量中

$date = '28 - 04 - 2015';
$date = strtotime(str_replace(' ', '', $date)); // Remove the spaces from your date and convert it into a time
$date = strtotime('+1 years', $date); // Add one year to the result
echo date('m - d - Y', $date); // Print the date 1 year later in the same format you had originally

结果是:

28 - 04 - 2016

如果你想把它放在一行:

$date = strtotime('+1 years', strtotime(str_replace(' ', '', $date)));
date('d - m - Y', strtotime($date . ' +1 years'));