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. Quote Link to comment Share on other sites More sharing options...
trq Posted January 14, 2009 Share Posted January 14, 2009 Id use strtotime and date. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
garry Posted January 14, 2009 Author Share Posted January 14, 2009 Brilliant, thanks a lot Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.