To modify the format of the year in PHP, we can use the date() function which returns the formatted date. The date() function accepts two parameters:
Here are some examples of modifying the format of the year:
$originaldate = "2019-05-15"; $newdate = date("y-m-d", strtotime($original_date)); // Output: 19-05-15
$originaldate = "2019-05-15"; $newdate = date("d-m-Y", strtotime($original_date)); // Output: 15-05-2019
$originaldate = "2019-05-15"; $newdate = date("y-m-d", strtotime($original_date)); // Output: 19-05-15
$originaldate = "2019-05-15"; $day = date("jS", strtotime($originaldate)); // Output: 15th
By using the date function with arguments as per the requirement, we can modify the format of the year.
Asked: 2021-11-06 11:00:00 +0000
Seen: 9 times
Last updated: Aug 29 '22