简体   繁体   中英

datetime convertion to date only php

i'd like to convert this datetime that was generated by MySQL, i'd like to convert this to just Month and day. This is my current format 2012-09-17 00:55:56

and I want to convert it to September 17 only

how can I do this using PHP code?

Thanks in advance!

Why not do it directly in MYSQL using DATE_FORMAT()

SELECT DATE_FORMAT('2012-09-17 00:55:56','%M %d')

SQLFiddle Demo

date("F d",strtotime($datefromdatabase)); //with leading zero in date

要么

date("F j",strtotime($datefromdatabase)); //without leading zero in date

DateTime solution:-

$date = DateTime::createFromFormat('Y-m-d h:i:s', getDateSomeHow());
echo $date->format('F d');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM