This is a discussion on Re: [PHP] timestamp problem !! within the PHP General forums, part of the PHP Programming Forums category; > <?php > $timy = '20030714012548'; // time stamp from MySQL > echo strtotime = ($timy); > $date = ("Y-m-d&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
> <?php
> $timy = '20030714012548'; // time stamp from MySQL > echo strtotime = ($timy); > $date = ("Y-m-d" , $timy); > ?> You are so very close! <?php $timy = '20030714012548'; // time stamp from MySQL echo strtotime = ($timy); $date = date("Y-m-d" , strtotime( $timy )); ?> $timy isn't a unix timestamp, which is what date() is expecting. Chris |
|
|||
|
> Hi Chris..
> thanks but your code generate the following error > Warning: date() [function.date]: Unexpected error in ..... > what's wrong? any idea ?? Sorry. You just need to take out this line: echo strtotime = ($timy); either that, or change it to: echo strtotime( $timy ) . ' = ' . ($timy) . '<br>'; But more important than that, are you certain that MySQL is returning '20030714012548' as the value for the timestamp field? That doesn't look quite right. Alternately, you can return the value you need (to pass to the date() function) by making your query look like this: SELECT blah, UNIX_TIMESTAMP( field_name ) as field_name_unixtime FROM table WHERE blah. // run query $dataRow = mysql_fetch_assoc( $result ); echo date( 'Y-m-d', $dataRow['field_name_unixtime'] ); For more information on this and other date functions in MySQL (which, depending on your needs, should be the place to put your date manipulations), you can go to this page: http://www.mysql.com/doc/en/Date_and...functions.html Chris |
|
|||
|
Hi Chris..
thanks but your code generate the following error Warning: date() [function.date]: Unexpected error in ..... what's wrong? any idea ?? "Chris Boget" <chris@wild.net> wrote in message news:037401c34a43$4c460f70$8c01a8c0@ENTROPY... > > <?php > > $timy = '20030714012548'; // time stamp from MySQL > > echo strtotime = ($timy); > > $date = ("Y-m-d" , $timy); > > ?> > > You are so very close! > > <?php > $timy = '20030714012548'; // time stamp from MySQL > echo strtotime = ($timy); > $date = date("Y-m-d" , strtotime( $timy )); > ?> > > $timy isn't a unix timestamp, which is what date() is expecting. > > Chris > |