-1

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!

Japar S
  • 57
  • 1
  • 7

4 Answers4

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

EDIT: Sorry wrong format

Working example:
http://sandbox.onlinephpfunctions.com/code/148e670733af48fdde6fc37884550744defb6eca

Andreas
  • 23,610
  • 6
  • 30
  • 62
0
date('d - m - Y', strtotime($date . ' +1 years'));
Matt S
  • 14,976
  • 6
  • 57
  • 76
T.J. Compton
  • 405
  • 2
  • 11
0

You can update database using INTERVAL

UPDATE table SET date = DATE_ADD(date, INTERVAL 1 YEAR) 
abhayendra
  • 197
  • 6
0

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)));
Chin Leung
  • 14,621
  • 3
  • 34
  • 58