How to usegetdate() Function in PHP
The getdate() function returns an associative array containing information about a given timestamp. You can use it to extract the day, month, and year components.
PHP
<?php // Get the current date $date = getdate (); // Extract day, month, and year $day = $date [ 'mday' ]; $month = $date [ 'mon' ]; $year = $date [ 'year' ]; // Display the results echo "Day: $day, Month: $month, Year: $year" ; ?> |
Output
Day: 1, Month: 1, Year: 2024
How to Extract Day, Month and Year in PHP ?
Given a Date, the task is to extract day, month, and year from the date using PHP. There are various methods to extract day, month, and year, these are:
Table of Content
- Using date() Function
- Using DateTime Class
- Using getdate() Function
Contact Us