Adam Moss Adam Moss - 13 days ago 7
PHP Question

Adjust a PHP date to the current year

I have a PHP date in a database, for example 8th August 2011. I have this date in a strtotime() format so I can display it as I please.

I need to adjust this date to make it 8th August 2013 (current year). What is the best way of doing this? So far, I've been racking my brains but to no avail.

Answer
strtotime( date( 'd M ', $originaleDate ) . date( 'Y' ) );

This takes the day and month of the original time, adds the current year, and converts it to the new date. You can also add the amount of seconds you want to add to the original timestamp. For 2 years this would be 63 113 852 seconds.

Comments