Forum Moderators: coopster
My ultimate goal is to insert it into MySQL in a date field. I assume (maybe incorrectly) that the first thing I need to do is strip off the last 13 characters so that it reads 20081217. I am then hoping that I can simply insert that as the date into MySQL and it will figure out how to treat it as a date (maybe I will not be this lucky, but I think I read somewhere that this works).
So...this is a 2 part question:
1. is there a way to use rtrim() to trim a certain NUMBER of characters from the right side...all i can find is how to trim CERTAIN characters from the right side... Is there a better way than rtrim()?
2. is there a more direct or better approach to convert my string into a usable MySQL date format (i don't care about the time portion of this string)?
$tempdate = '20081217120000[0:GMT]';
$dateToInsert = substr($tempdate, 0, 4).'-'.substr($tempdate, 4, 2).'-'.substr($tempdate, 6, 2);
You could also try something like:
$dateToInsert = date('Y-m-d', strtotime($tempdate));
hope it helps :)
This works PERFECTLY:
$tempdate = '20081217120000[0:GMT]';
$dateToInsert = substr($tempdate, 0, 4).'-'.substr($tempdate, 4, 2).'-'.substr($tempdate, 6, 2);
This does not work (unfortunately):
$dateToInsert = date('Y-m-d', strtotime($tempdate));
Thanks again to you both!