How to format datetime field from MySQL in a select statement?
I have a column set to datetime and with a defined format of 0000-00-00 00:00:00, and 开发者_如何学Cnow I am trying to query with a SELECT statement to format that date after coming out.
I tried DATE_FORMAT(date_field,'%m-%d-%Y')
, but that didn't work. I want to just pull out the month-day-year...
Is this possible, or do I have to do it after the data has been pulled out and is a PHP function?
You would need to alias the DATE_FORMAT function so that the return field would be something that PHP can recognize.
Without an alias the outputted field would be:
$DATE_FORMAT(date_field,'%m-%d-%Y')
With an alias:
$date_field
精彩评论