Roy Barten Posted February 20, 2009 Share Posted February 20, 2009 Hello, here the following problem. I have a date from an array looks like this 2009-03-02 10:00. But now i want a variable with the same value, but only the date, and not the time. So $date = 2009-03-02 10:00 I want $date2 = 2009-03-02 How do i do this? Link to comment https://forums.phpfreaks.com/topic/146084-solved-split-dates/ Share on other sites More sharing options...
genericnumber1 Posted February 20, 2009 Share Posted February 20, 2009 A lot of ways, the easiest would just be to do <?php $date = '2009-03-02 10:00'; $date2 = substr($date, 0, 10); if you're a magic constants nazi... <?php $date = '2009-03-02 10:00'; $date2 = substr($date, 0, strpos($date, ' ')); Link to comment https://forums.phpfreaks.com/topic/146084-solved-split-dates/#findComment-766896 Share on other sites More sharing options...
thebadbad Posted February 20, 2009 Share Posted February 20, 2009 Or you can explode it and list() the vars in the same go: <?php $date = '2009-03-02 10:00'; list($date2, $time) = explode(' ', $date); ?> Link to comment https://forums.phpfreaks.com/topic/146084-solved-split-dates/#findComment-766914 Share on other sites More sharing options...
Mchl Posted February 20, 2009 Share Posted February 20, 2009 Or you can use strtotime() $date = '2009-03-02 10:00'; $date2 = date("Y-m-d",strtotime($date)); Link to comment https://forums.phpfreaks.com/topic/146084-solved-split-dates/#findComment-766920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.