I am retrieving date from MySQL in the format yyyy/mm/dd 00:00:00. I want to convert this date into format dd/MMM/yyyy in PHP.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use PHP’s date and strtotime:
$formatted = date('d/M/Y', strtotime($date_from_mysql));Or use MySQL’s built in DATE_FORMAT function:
SELECT DATE_FORMAT(datetime, '%d/%b/%Y') datetime FROM tableOr, you can mix a bit of both flavours:
The last method is handy if you need to get several different formats on the same page; say, you would like to print the date and time separately, then you can just use date(‘d/M/Y’, $timestamp) and date(‘H:i’, $timestamp) without any further conversions.