do you know if ther's any method in MySql that can transform a DATE field into a string? Example The date in MySql format is something like 2002-12-08 but I want it to be returned as 2002December08. I want to use this on a PHP page displaying data from the databse....
With questions like these, it pays to first check the manual. In this case you would have found DATE_FORMAT() in the mysql manual.
<? $date = "2002-12-08"; $d_array = explode("-", $date); $year = $d_array["0"]; if ($d_array["1"] == '1') { $month = "Januray"; } elseif ($d_array["1"] == '2') { $month = "February"; } elseif ($d_array["1"] == '3') { $month = "March"; } elseif ($d_array["1"] == '4') { $month = "April"; } elseif ($d_array["1"] == '5') { $month = "May"; } elseif ($d_array["1"] == '6') { $month = "June"; } elseif ($d_array["1"] == '7') { $month = "July"; } elseif ($d_array["1"] == '8') { $month = "August"; } elseif ($d_array["1"] == '9') { $month = "September"; } elseif ($d_array["1"] == '10') { $month = "October"; } elseif ($d_array["1"] == '11') { $month = "November"; } elseif ($d_array["1"] == '12') { $month = "December"; } $day = $d_array["2"]; echo "Todays Date is " . $year . $month . $day . ""; ?>
I still think that
SELECT DATE_FORMAT('%Y %M %D') FROM table;
is a lot easier...
Yeah, it is. I completely forgot about mysql's DATE_FORMAT(). We must have posted at the same time, and when he said PHP page, I thought if statement. 🙂