MySQL and PHP Date Formt

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
Can anyone tell me why it displays 01 Jan 1970 instead of my date in the database?

PHP:
echo date('d M Y',$row['time']);

Seems to me it's ignoring the $row
 
to test if its echoing the time out, on a separate line just echo $row['time'] out to see if its not being pulled properly or if youre doing something wrong with the function :)
 
It's echoing the correct value on a seperate line (without the date function).

But when I try and format it as above it just reverts to 01 Jan 1970.
 
Thanks for the reply but it's still the same result 01 Jan 1970.

Could it be a problem at the database end? Do I have to change my select statement at all?

dateyl6.jpg


Can't see anything wrong here?
 
Dj_Jestar said:
Code:
SELECT UNIX_TIMESTAMP(`Date`) AS `TimeStamp` FROM `Table`

Ok now I'm confused.

Here is my current Select statement:

SELECT comp, time, firstteam, secondteam FROM upcoming

Which I echo all the above including:

echo date('d M Y', intval($row['time']));

But still have the same problem.
 
the suggestion of using unix_timestamp function should work fine, just try that.

The problem is that PHP's date function expects a timestamp (seconds since 1970), not a formatted date (which your query will produce)
 
JamesU2005 said:
So how would I adjust me select and echo?

Code:
$result = mysql_query("SELECT comp, UNIX_TIMESTAMP(time) AS stamp, firstteam, secondteam FROM upcoming");

while ( $row = mysql_fetch_assoc($result) ) {
    echo date('d M Y', $row['stamp']);
}
 
robmiller said:
Code:
$result = mysql_query("SELECT comp, UNIX_TIMESTAMP(time) AS stamp, firstteam, secondteam FROM upcoming");

while ( $row = mysql_fetch_assoc($result) ) {
    echo date('d M Y', $row['stamp']);
}

Thank you, thank you, thank you!

Can't believe something as simple as formatting a date caused some many problems.

Also thanks to all those that tried to help.
 
JamesU2005 said:
Thank you, thank you, thank you!

Can't believe something as simple as formatting a date caused some many problems.

Also thanks to all those that tried to help.

Is this the point where I point out that that's a really silly way of doing it and that you should just format the date with SQL

Code:
SELECT DATE_FORMAT(time, '%D %M %Y') FROM upcoming
 
JamesU2005 said:
Can anyone tell me why it displays 01 Jan 1970 instead of my date in the database?

Code:
echo date('d M Y',$row['time']);

Seems to me it's ignoring the $row

If you don't want to change your sql, you could use the php function strtotime(). I had this problem earlier this week.

Code:
echo date('d M Y',strtotime($row['time']));
 
Back
Top Bottom