hstraf
November 19, 2006, 4:29pm
1
Hello,
I need to somehow convert dates from one format to another.
The “old” format looks like this:
04 May 6 7:16
05 Apr 23 12:42
05 Jul 3 17:54
The new format needs to be like this:
yyyy-mm-dd
Is this possible? Is there a relatively easy way to do this?
Look at mktime() .
You should split the time into day month year minute and second (you will need to turn the month into a number) and then you should be able to use mktime:
echo date("Y-m-d", mktime($hour, $minute, $second, $month, $day, $year));
This sould output the date in the format yyyy-mm-dd
or
echo date("Y-m-d",strtotime($time));
OK - forget my method php_deamon’s way is much better
hstraf
November 19, 2006, 5:16pm
5
It’s close, but with the source date of “06 Apr 25 13:36” I end up with a converted date of “2025-04-06”.
I’ll see if I can try and split up the original date components or something…
hstraf
November 19, 2006, 5:35pm
6
I ended up with this:
$original_date = “06 Apr 25 13:36”;
$pieces = explode(" “, $original_date);
$new_date = date(“Y-m-d”,strtotime($pieces[2].” “.$pieces[1].” ".$pieces[0]));
Thanks folks!