How to Get the Current Year using PHP PHP date() function is used for getting date. You can customize the output by passing the values to the function. For example, to get the current year pass “Y” to the function. This will show you the current date only. Use below sample PHP program to print current year.
1 2 3 4 5 6 7 | <?php // PHP program to get the current year echo "Current Year is :"; $year = date("Y"); echo $year; ?> |
This is also useful for the printing the copyright statement with the current year at the footer of your website. For example add below state to your php script footer file.
1 2 3 | <p> Copyright © <?php echo date("Y"); ?> example.com. All Rights Reserved. </p> |