Jump to content

[SOLVED] Trimming text from and to ...


chrisfane

Recommended Posts

im not sure which function i should use to trim a number of charactors from the end of my string.  i already have a timestamp i nthe form of ...

 

2007-08-26 12:35:29

 

in my database, i need to split this into a separate time and date, which unfortunatly cant be done at the time of writing.  to do this i propose trimming after ten charators, or anything after and including the space, and then on a second pass trimming everything before and including the space.  my question is...

 

Which function would should i use to do this ?

 

everything i have previously found can trim by charactor, but not by number.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/67450-solved-trimming-text-from-and-to/
Share on other sites

$date = '2007-08-26 12:35:29';
echo substr($date, 0, 10); //prints '2007-08-26'
echo substr($date, 10) //prints '12:35:29'

 

or

 

$date = '2007-08-26 12:35:29';
$expl = explode(' ', $date);
echo $expl[0]; //prints '2007-08-26'
echo $expl[1]; //prints '12:35:29'

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.