Jump to content

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'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.