19

Possible Duplicate:
How do I use PHP to get the current year?

2009 this year, 2010 next year.

Community
  • 1
  • 1
omg
  • 136,412
  • 142
  • 288
  • 348
  • 4
    Possible duplicate: http://stackoverflow.com/questions/64003/how-do-i-use-php-to-get-the-current-year – Mr. Smith Aug 31 '09 at 06:07

5 Answers5

44

Look at the functions date() and strtotime():

echo date('Y');
echo date('Y', strtotime('+1 year'));
NSSec
  • 4,431
  • 1
  • 27
  • 29
18

You can use the date function to extract a part of a date:

$year = date("Y"); // get the year part of the current date
$nextYear = $year + 1;

Run the snippet here.

Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
13
<?php
$date="2010-04-30";
$y = date('Y',strtotime($date));
echo $y; 
?>
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Nachi
  • 131
  • 1
  • 2
1

Use getdate() function

Chathuranga Chandrasekara
  • 20,548
  • 30
  • 97
  • 138
1

...and strftime('%Y') does it too

Saty
  • 22,443
  • 7
  • 33
  • 51