Re: converting a mysql date value
| From: | Steve Staples | Date: | Wed, 29 Sep 2010 19:35:36 +0000 |
| Subject: | Re: converting a mysql date value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308360@lists.php.net to get a copy of this message | ||
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.
>