i have db with date format like this : 28 - 04 - 2015
how to add that data +1 year with php?
any idea?
Thanks very much!
i have db with date format like this : 28 - 04 - 2015
how to add that data +1 year with php?
any idea?
Thanks very much!
echo date('d - m - Y', strtotime('+1 years', strtotime(str_replace(" ", "",$DateFromDB))));
EDIT: Sorry wrong format
Working example:
http://sandbox.onlinephpfunctions.com/code/148e670733af48fdde6fc37884550744defb6eca
You can update database using INTERVAL
UPDATE table SET date = DATE_ADD(date, INTERVAL 1 YEAR)
Let's say you save the value of your date in the variable named $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
The result would be:
28 - 04 - 2016
If you want it in one line:
$date = strtotime('+1 years', strtotime(str_replace(' ', '', $date)));