On 16/11/2004, at 6:29 AM, Robert Sossomon wrote:
I have a date in format YY-MM-DD in a MySQL table. I need to pull it back to display it in either format: MM-DD-YY or Month Day, Year format.
Do it in PHP, not in the query, IMHO.
<? $date = "04-11-28"; list($year,$month,$day) = explode('-',$date); $date = "{$month}-{$day}-{$year}"; ?>
You can also experiment with strtotime()... the catch will be the 2 digit year format, so you might have to either
a) assume the first two digits
b) accept PHP's assumptions on the first two digits
c) fix your database now into 4 digit format, to make it future proof and a lot more solid
<? $date = "04-11-28"; $date = strtotime($date); $date = date("F jS, Y"); ?>
The reason I wouldn't do this in the query is that you're relying on features of the particular SQL platform, version or table. By moving that conversion back to PHP and keeping your queries simple and as standard as possible, you're going to be a lot happier if your environment changes.
But that's just the way I work :)
Justin
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php