Prev: Which PHP 5.3 documentation generators have you found?
Next: RES: [PHP] converting a mysql date value
From: David Mehler on 29 Sep 2010 15:11 Hello, I've got dates stored in a mysql database. The field is of type date so the value is something like: "2010-09-29" I'm wanting to display them as in U.S. dates as in month, day, year. I had a function that did this, now it is not working and I am perplexed as to why. Here's my echo statement: <?php echo sqlDateFormat($row['date']); ?> The $row['date'] is coming out of the mysql database. Here's the sqlDateFormat function: function sqlDateFormat($value) { $date = $value; $date = strtotime($date); $date = date('m-d-y', $date); return $date; } I'd appreciate any suggestions as to why this isn't working. Thanks. Dave.
From: Adam Richardson on 29 Sep 2010 15:19 On Wed, Sep 29, 2010 at 3:11 PM, David Mehler <dave.mehler(a)gmail.com> wrote: > Hello, > I've got dates stored in a mysql database. The field is of type date > so the value is something like: "2010-09-29" I'm wanting to display > them as in U.S. dates as in month, day, year. I had a function that > did this, now it is not working and I am perplexed as to why. Here's > my echo statement: > > <?php echo sqlDateFormat($row['date']); ?> > > The $row['date'] is coming out of the mysql database. Here's the > sqlDateFormat function: > > function sqlDateFormat($value) { > $date = $value; > $date = strtotime($date); > $date = date('m-d-y', $date); > return $date; > } > > I'd appreciate any suggestions as to why this isn't working. > Thanks. > Dave. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > What's being echoed out? Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
From: Steve Staples on 29 Sep 2010 15:35
http://www.w3schools.com/sql/func_date_format.asp when you do your select, "SELECT DATE_FORMAT(`field_name`,'%b %d %Y %h: %i %p') AS 'field_name'" which would yield you the field "field_name": 'Nov 04 2008 11:45 PM' would be easier to do it there, rather than in your PHP... and you can change the date_format in your query via PHP if you need to change it on the fly... if the dates were in UNIX TIME, you can do it like: SELECT DATE_FORMAT(FROM_UNIXTIME(`field_name_in_unix_timestamp`),'%b %d %Y %h:%i %p'); Steve On Wed, 2010-09-29 at 15:11 -0400, David Mehler wrote: > Hello, > I've got dates stored in a mysql database. The field is of type date > so the value is something like: "2010-09-29" I'm wanting to display > them as in U.S. dates as in month, day, year. I had a function that > did this, now it is not working and I am perplexed as to why. Here's > my echo statement: > > <?php echo sqlDateFormat($row['date']); ?> > > The $row['date'] is coming out of the mysql database. Here's the > sqlDateFormat function: > > function sqlDateFormat($value) { > $date = $value; > $date = strtotime($date); > $date = date('m-d-y', $date); > return $date; > } > > I'd appreciate any suggestions as to why this isn't working. > Thanks. > Dave. > |