Re: [PHP] Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)
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" <[EMAIL PROTECTED]> To: "Matthew Ralston" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)
Thanks Papi, That works fine. Matt [EMAIL PROTECTED] < www.mralston.co.uk /> Pavel Jartsev <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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: Hope this helps. -- Pavel a.k.a. Papi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)
Mathew, Great that they're backwards from one another, isn't it? The regular expression wizards probably have some marvellous trick up their sleeve, and Manuel Lemos probably has a class that will do this. You can do it yourself by using substring functions to extract the parts of the date, rearrange it and then, if you wish, use a couple of lookup arrays to fetch months and extensions like "st rd ..". But better that, aren't there date extraction functions in MySQL you can use in your select statement? Or, even better, and this is a personal crusade, "Let's train the world to use a logical date format: -mm-dd!!" (Isn't this an ISO Standard, which should be acceptedin the UK and in Europe?) Here's some extraction stuff I messed around with about a year ago...$dtAuctionStart is mmdd MySql date, no hyphens. Some messing about with dates = echo $dtAuctionStart, ""; echo date ("Y-m-d", $dtAuctionStart ), ""; //$strDate = $dtAuctionStart ; echo "dtAuctionStart : $dtAuctionStart"; $year = substr ($dtAuctionStart, 0, 4); $month = substr( $dtAuctionStart, 4, 2 ); $day = substr ($dtAuctionStart, 6, 2 ); Echo "dtAuctionStart in m-d -y : $month-$day-$year "; $workdate = getdate( $dtAuctionStart ); echo " Workdate Year:", $workdate["year"],""; Ereg Stuff == if (ereg ("([0-9]{4})([0-9]{1,2})([0-9]{1,2})", $dtAuctionStart, $regs)) { echo "Auction Start: $regs[1]-$regs[2]-$regs[3] "; } else { echo "Bad date format. "; } Have fun - Miles At 01:57 PM 5/23/01 +0100, 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? > >-- >Thanks, > >Matt >[EMAIL PROTECTED] >< www.mralston.co.uk /> > > > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] >To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)
You could consider using DATE_FORMAT() when pulling the date out of the MySQL Table. HAve a look in the mysql manpages for the ezxact syntax Wieger 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? > > -- > Thanks, > > Matt > [EMAIL PROTECTED] > < www.mralston.co.uk /> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Wieger Uffink tel: +31 20 428 6868 fax: +31 20 470 6905 web: http://www.usmedia.nl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Converting MySQL Date (2001-05-21) to Friendly Date (21 May 2001)
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? -- Thanks, Matt [EMAIL PROTECTED] < www.mralston.co.uk /> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]