Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date; How to find the next year?

Tags:

I want to get today's date + one year. How do I achieve this with PHP's date functions?

like image 559
Testadmin Avatar asked Sep 16 '10 07:09

Testadmin


People also ask

How do I get this year in PHP?

To get the current year using PHP's date function, you can pass in the “Y” format character like so: //Getting the current year using //PHP's date function. $year = date("Y"); echo $year; The example above will print out the full 4-digit representation of the current year.

How can change year in date in PHP?

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.

How do I get this year start and end in PHP?

$year = date('Y') - 1; // Get current year and subtract 1 $start = mktime(0, 0, 0, 1, 1, $year); $end = mktime(0, 0, 0, 12, 31, $year);


2 Answers

echo date('Y', strtotime('+1 year')); 
like image 200
gianebao Avatar answered Oct 01 '22 05:10

gianebao


You can use strtotime and date

$date = '2010-09-16'; echo date('Y-m-d', strtotime("+12 months $date")); // 2011-09-16 

On a sidenote: DateTime questions like this have been answered over and over again, so you could have found how to add to a date easily by using the search function.

like image 30
Gordon Avatar answered Oct 01 '22 06:10

Gordon