garry Posted January 14, 2009 Share Posted January 14, 2009 So I have a string containing a date and time in the following format 22 Oct 2008 12:45:00 PM Basically, I need some sort of regex to split up the date and the time into two different variables.. I've tried playing around with some but I haven't quite got it, i'm not so great at expressions. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/140802-solved-help-with-a-string/ Share on other sites More sharing options...
trq Posted January 14, 2009 Share Posted January 14, 2009 Id use strtotime and date. Link to comment https://forums.phpfreaks.com/topic/140802-solved-help-with-a-string/#findComment-736951 Share on other sites More sharing options...
garry Posted January 14, 2009 Author Share Posted January 14, 2009 When I try to put a date of that format into the date() function, it returns Thu, 01 Jan 1970 10:00:22. So i'm going to have a wild guess that it's an incorrect format? Link to comment https://forums.phpfreaks.com/topic/140802-solved-help-with-a-string/#findComment-736959 Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 You need to use the strtotime function on the string before passing it to the date function: <?php $str = '22 Oct 2008 12:45:00 PM'; echo date('Y-m-d',strtotime($str)) . "<br>\n"; echo date('g:i',strtotime($str)) . "<br>\n"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/140802-solved-help-with-a-string/#findComment-736963 Share on other sites More sharing options...
garry Posted January 14, 2009 Author Share Posted January 14, 2009 Brilliant, thanks a lot Link to comment https://forums.phpfreaks.com/topic/140802-solved-help-with-a-string/#findComment-736967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.