neddry Posted August 12, 2009 Share Posted August 12, 2009 Hey I am looking into a function that could grab the info between two characters what I have at the moment is a loop and in the loop I want to strip the time from the datetime stamp default: 2009-08-12T01:00:00+01:00 so what I am trying to get is the variable between the T and the + Could anyone point me in the right direction? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/169994-solved-getting-the-content-between-to-characters/ Share on other sites More sharing options...
perrij3 Posted August 12, 2009 Share Posted August 12, 2009 I think you have to explode the information. Here is an example of a date that I explode. The date came from a MySQL Database and saved in the format (Y-M-D) if (isset($visitrow['Date'])) { $date = explode('-', $row['Date']); $month = $date[1]; $day = $date[2]; $year = $date[0]; } Quote Link to comment https://forums.phpfreaks.com/topic/169994-solved-getting-the-content-between-to-characters/#findComment-896776 Share on other sites More sharing options...
Philip Posted August 12, 2009 Share Posted August 12, 2009 Using the datetime class you can extract any part you need: $d = date_create('2009-08-12T01:00:00+01:00'); echo date_format($d, 'm/d/Y -- H:i:s P'); Look at date for the formatting strings.... Edit: (this is given you're using PHP 5.2+, if not there are still ways to do it - but this class has made it easier) Quote Link to comment https://forums.phpfreaks.com/topic/169994-solved-getting-the-content-between-to-characters/#findComment-896792 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2009 Share Posted August 12, 2009 You could also use regexp. <?php $str = '2009-08-12T01:00:00+01:00'; preg_match('/[0-9-]*T(.*)\+/', $str, $matches); var_dump($matches[1]); // 01:00:00 Quote Link to comment https://forums.phpfreaks.com/topic/169994-solved-getting-the-content-between-to-characters/#findComment-896796 Share on other sites More sharing options...
neddry Posted August 12, 2009 Author Share Posted August 12, 2009 Thanks for your prompt replies. I ended up using the explode with substr to get it exact. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/169994-solved-getting-the-content-between-to-characters/#findComment-896805 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.