Snippets

Get Current Year in PHP

Posted by I. B. Gd Pramana A. Putra, 07 Aug 22, last updated 08 Aug 22

Suppose you want to retrieve or get current year in PHP, you can use the following method to accomplish this.

<?php 
// PHP program to get the current year

$year = date("Y"); 
  
// Display the year
echo "current year is " . $year; 
  
?> 

Notice that we use date() function with PHP and supply the parameter with Y as argument. Y will be automatically treated as Year.

Source: PHP - Date

I love sharing code snippets as most of the time, a quick code example is what we're looking for instead of long-written articles. If you think my code snippets are helpful and save you a lot of time, please consider buying me a cup of coffee :)

Support me via · paypal · buymeacoffee · ko-fi · trakteer
Contributed Snippets
Answer & Responses
    No comments yet

Wanna write a response?

You have to login before write a comment to this post.