Re: [PHP] timestamp problem !!

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&...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-14-2003
Chris Boget
 
Posts: n/a
Default Re: [PHP] timestamp problem !!

> <?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

Reply With Quote
  #2 (permalink)  
Old 07-15-2003
Chris Boget
 
Posts: n/a
Default Re: [PHP] timestamp problem !!

> 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

Reply With Quote
  #3 (permalink)  
Old 07-15-2003
Nabil
 
Posts: n/a
Default Re: [PHP] timestamp problem !!

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
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:16 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0