Splitting Datetime into a date and a time value

后端 未结 7 1901
暖寄归人
暖寄归人 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 02:03

    One simple instruction will do the trick

    explode will transform datetime to an array

    and list will sort the datetime array into its needed values

    $datetime = "28-1-2011 14:32:55";
    list($date, $time)=explode(' ', $datetime);
    
    // check the result
    echo "date:". $date;
    echo "
    time:". $time; // further more you can easily split the date into // year month and day list($year, $month, $day)=explode('-', $date);

提交回复
热议问题