php timestamp shows bad format

javiermorquecho
javiermorquecho used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
use strtotime() function...
Most Valuable Expert 2011
Top Expert 2016

Commented:
Probably like this
echo date("j, n, Y", strtotime($dates[$i]));

Open in new window

Most Valuable Expert 2011
Top Expert 2016

Commented:
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
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Author

Commented:
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

Most Valuable Expert 2011
Top Expert 2016

Commented:
What format do you want for the date that you print out?  I think we have got it partway there.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Your pattern string for the date() function is documented on the man page here:
http://us2.php.net/manual/en/function.date.php
Most Valuable Expert 2011
Top Expert 2016
Commented:
@javiermorquecho: One other thing, please.  Please post the code you are using now to print the date.  What you have posted above does not seem to be consistent with the output you posted.  Thanks, ~Ray

Author

Commented:
Yep Ray, you´re right!

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

Thnx

Author

Commented:
Thnx Ray...you the best!
Most Valuable Expert 2011
Top Expert 2016

Commented:
Excellent - thanks for the points, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial