How get current year in PHP?

by raphael_tillman , in category: PHP General , 2 years ago

How get current year in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by aubrey , 2 years ago

@raphael_tillman 

To get the current year in PHP, you can use the date function with the Y format string. For example:

1
$currentYear = date('Y');


This will return the current year as a 4-digit integer. For example, if the current year is 2021, it will return 2021.


You can also use the date function to get the current year, month, and day separately, using the Y, m, and d format strings, respectively.


For example:

1
2
3
$currentYear = date('Y');
$currentMonth = date('m');
$currentDay = date('d');


This will return the current year, month, and day as 4-digit, 2-digit, and 2-digit integers, respectively. For example, if the current date is January 3, 2021, it will return 2021, 01, and 03, respectively.

Member

by lew , a year ago

@raphael_tillman 

To get the current year in PHP, you can use the date function with the 'Y' format parameter. Here's an example:

1
2
$currentYear = date('Y');
echo $currentYear;


This will output the current year.