I have a string
$string = "2012-1-12 51:00:00.5";
How can I explode this date into year, month, day, hour, minutes, seconds without using a date function.
I was trying with multiple calls of explode()
because it can only split on one delimiter at a time, but this isn't working out well.
My try:
$string = "2012-1-12 51:00:00.5";
print_r(explode(" ", $date));
print_r(explode("-", $date));
print_r(explode(":", $date));
Output:
Array
(
[0] => Array
(
[0] => 2012-1-12
[1] => 51:00:00.5
)
[1] => Array
(
[0] => 2012
[1] => 1
[2] => 12 51:00:00.5
)
[2] => Array
(
[0] => 2012-1-12 51
[1] => 00
[2] => 00.5
)
)