Open In App

How to get current year in PHP ?

The Date is an inbuilt function used to format the timestamp. The computer stores date and time in UNIX Timestamp. This time is measured as a number of seconds since Jan 1, 1970. Since this is impractical for humans to read, PHP converts timestamp to a format that is readable and more understandable to humans.

Syntax:



date( format, timestamp )

Explanation:

In order to get the current year as four digits, Y is used as a parameter to date() function as shown in the below:



Program:




<?php 
// PHP program to get the
// current year
  
echo "Current Year is :"
  
// Store the year to
// the variable
$year = date("Y"); 
  
// Display the year
echo $year
  
?> 

Output:
Current Year is :2019

Format options available in date() function: The format parameter of the date() function is a string that can contain multiple characters allowing to generate dates in various formats are listed below:

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.

Article Tags :