Page 1 of 1
getting date out of mysql
Posted: Wed Sep 17, 2003 5:25 am
by yaron
Hi all,
I have this starnge problem.
I try to get the datetime field out of mysql.
I use:
$arr=sql_fetch_array($result)
$date=$arr['mdate'];
This code used to work fine and I got the date in the format yyyy-mm-dd H:i:s just as it is in the db.
but now I use php 4.33 and I get just the year int the $date variable.
In the old version things still work good.
What is the problem?
Posted: Wed Sep 17, 2003 5:55 am
by JAM
I guess that you made a typo; mysql_fetch_array?
Anyways, it sounds very wierd. How do you verify that its 'yyyy-mm-dd H:i:s' actually is stored in the database?
Posted: Wed Sep 17, 2003 6:05 am
by yaron
yea yea it's mysql_fetch_array() ofcourse.
in can see in the phpmyadmin that this field is entered correctly.
No difference from the other version...
quite a puzzle isn't it?!
Posted: Wed Sep 17, 2003 6:54 am
by twigletmac
What do you get if you use print_r() on the row array, e.g.:
Code: Select all
$row = mysql_fetch_array($result);
echo '<pre>';
print_r($row);
echo '</pre>';
Does that date show up properly there? It may also be useful to see the SQL statement that you use to draw the information from the database.
Mac
Posted: Wed Sep 17, 2003 7:03 am
by yaron
It still prints only the year.
in the db it apears 2003-09-08 16:55:02
and the same code works in another version...
As for my sql statement it was just: SELECT * FROM table
nothing complex and should get all fields and it does but the date appears starnge!!
Posted: Wed Sep 17, 2003 8:51 am
by Bill H
My guess would be something to do with conversion to an integer variable. PHP is not strongly typecast, but if you convert the string "2003-12-15 etc" into an interger variable and than back into a string you will get "2003" alone.
Not seeing all of your code is a handicap in diagnosing the problem, but look for anything that may be casting that element to an integer. Something in the more recent version may be more strongly typecasting than in the earlier version.
Posted: Wed Sep 17, 2003 10:19 am
by yaron
Ohhhhh...
I found my stupid mistake.....
The field type was decimal and not datetime (of course in the old system it was datetime).
Sorry to waste your time on such a stupid mistake.
and Thank you Bill H - your conversion idea made me look in the right place