Re: Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)

From: Date: Wed, 23 May 2001 15:49:34 +0000
Subject: Re: Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-54043@lists.php.net to get a copy of this message
You could shorten it by having mysql convert the date into a timestamp: $result = mysql_query("SELECT UNIX_TIMESTAMP(date) as somedate FROM dates"); $row = mysql_fetch_array($result); echo date("jS F Y", $row[somedate]); Ethan ----- Original Message ----- From: "Pavel Jartsev" <papi@digitalfruit.ee> To: "Matthew Ralston" <matthew.ralston@haltoncollege.ac.uk>; <php-general@lists.php.net> Sent: Wednesday, May 23, 2001 6:21 AM Subject: Re: [PHP] Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001) > Matthew Ralston wrote: > > > > I've got a date stored in a MySQL database in a "DATE" field, so it is > > stored as "2001-05-21". How do I convert that into a more friendly date like > > "21 May 2001" or even "21st May 2001" for display on a web page? > > > > I've tried > > > > print date("jS F Y", $dbtable[date]); > > > > but I always get "1st January 1970" because I don't know how to convert the > > MySQL date into a PHP timestamp. > > > > Can someone tell me how to do it please? > > > > Maybe it's not very nice, but it works: > <? > list($y,$m,$d) = explode('-', $dbtable['date']); > print date("jS F Y", mktime(0, 0, 0, $m, $d, $y)); > ?> > > > Hope this helps. > > -- > Pavel a.k.a. Papi > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#54043) next »