Jump to content

[SOLVED] Getting the content between to characters


neddry

Recommended Posts

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

 

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];
	}

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.