get the current year in PHP


Answers ( 1 )


    To get the current year in PHP, you can use the date() function. The date() function in PHP is used to format a local date and time, and it can be used to get the current year. Here's an example of how you can use it to get the current year:

    $currentYear = date("Y");
    echo $currentYear;

    In this example, date("Y") will return the current year in four digits. For example, if the current year is 2024, it will return '2024'.

    There are not many variations to this solution as the requirement is quite straightforward. However, if you need the year in a different format (like a two-digit format), you can modify the format string passed to the date() function. For example, date("y") will return the current year in two digits (e.g., '24' for the year 2024).

Leave an answer