What is the best way to determine the year of a specific date in PHP?
To determine the year of a specific date in PHP, you can use the date() function along with the 'Y' format character, which represents the year in a four-digit format. This function allows you to extract the year from a given date string or timestamp.
$date = '2022-09-15';
$year = date('Y', strtotime($date));
echo $year; // Output: 2022
Keywords
Related Questions
- How can PHP be used to check if new values already exist in a database before performing an update?
- What potential issues or errors could arise when using the getTemplate function in the Template Class?
- What are the potential implications of using PHP version 5.4.16 in relation to the CURLFile class?