- PHP

How to get the Year in PHP

How to get the current year in PHP

Use date(“Y”).

Example:

<?php

$year = date("Y");

echo 'Current year: ' . $year;

?>

How to get the year from the timestamp in PHP

Use date() function with arguments such as “Y” and your timestamp.

Example:

<?php

$timestamp = 946684800;

$year = date("Y", $timestamp);

echo $year;

?>

Output: 2000

How to get the year from the date in PHP

Use the combination of date() and strtotime() function.

Example:

<?php

$date = "1990-04-01";

$year = date("Y", strtotime($date));

echo $year;

?>

Output: 1990