开发者

How to format datetime field from MySQL in a select statement?

开发者 https://www.devze.com 2023-02-01 00:03 出处:网络
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 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号