Home >Database >Mysql Tutorial >How to Format Dates as dd/mm/yyyy in PHP and MySQL?
How to Display Dates in dd/mm/yyyy Format in PHP MySQL
Problem:
By default, MySQL stores dates in the 'YYYY-MM-DD' format. However, it is often desirable to display dates in the more familiar 'dd/mm/yyyy' format. How can this be achieved using PHP MySQL?
Answers:
Using PHP:
Example:
Note that this method is limited to dates within the range of 1970 to 2038 due to timestamp limitations.
Using MySQL:
The date_format() function in MySQL can be used to format dates.
Example:
This will return the current date in the 'dd/mm/yyyy' format.
Using DateTime Class:
The DateTime class in PHP provides a more flexible approach that avoids the limitations of timestamps.
Example:
This will output the date as '19/03/2010'.
The above is the detailed content of How to Format Dates as dd/mm/yyyy in PHP and MySQL?. For more information, please follow other related articles on the PHP Chinese website!