In my mysql database I have dates like this: 2011-01-06 09:39:114525
and I need to extraxt separately years, months, days, hours, minutes, seconds from it.
S
Old thread, but I couldn't resist posting the obvious 'brute-force' solution:
If your SQL date-time string format is always given as in your example, and you don't want to use date-time functions/classes, you can do the following:
$mysql_datetime = "2011-01-06 09:39:114525";
list($date, $time) = explode(' ', $mysql_datetime);
list($year, $month, $day) = explode('-', $date);
list($hr, $min, $sec) = explode(':', $time);
$sec = (int)substr($sec, 0, 2);
The values you want are now available in the following variables: $year, $month, $day, $hr, $min, $sec
.