Link to home
Start Free TrialLog in
Avatar of javiermorquecho
javiermorquechoFlag for Mexico

asked on

php timestamp shows bad format

Hi Experts!

I ´ve a field in my table with the format timestamp.

I´ve data like:

2009-10-22 15:13:55

I filled with NOW() function ( SQL ).

When I try the code ( show the code section ), shows me something like:

31, 12, 1969

Whats wrong???

Thnx


echo date("j, n, Y", $dates[$i] );  //$dates[$i] is the field value

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

use strtotime() function...
Probably like this
echo date("j, n, Y", strtotime($dates[$i]));

Open in new window

If you try that and still have trouble with the dates, print out the contents of $dates[$i] and see if it is a DATETIME value like the ISO8601date / time thing.  YYYY-MM-DD HH:MM:SS  strtotime() can interpret those values into a UNIX timestamp and date() can cover the timestamp into a human-readable date string.

Best regards, ~Ray
Avatar of javiermorquecho

ASKER

when I put the code attached, I see that:

0-/-1/2009

The field format is a timestamp, the structure is that. But,

What minds that?

echo $dates[$i];

Open in new window

What format do you want for the date that you print out?  I think we have got it partway there.
Your pattern string for the date() function is documented on the man page here:
http://us2.php.net/manual/en/function.date.php
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yep Ray, you´re right!

The problem is that other class modify the data....All is OK.

Thnx
Thnx Ray...you the best!
Excellent - thanks for the points, ~Ray