Splitting Datetime into a date and a time value

后端 未结 7 1908
暖寄归人
暖寄归人 2020-12-11 01:21

Can someone give me a quick and dirty way to split a datetime (28-1-2011 14:32:55) into just the date (28-1-2011) and the time ( 14:32 ) or even better (2:32 PM) using PHP.

7条回答
  •  长情又很酷
    2020-12-11 01:47

    if your source of data is MySQL:

    SELECT DATE( date_field ) AS date_part, TIME( date_field ) AS time_part ....
    

    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_time

    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date

    Edit : to answer the question from comments (example):

    WHERE DATE( date_field ) > '2017-01-01'
    

提交回复
热议问题