Forum Moderators: coopster

Message Too Old, No Replies

date and time

         

yllai

6:11 am on May 6, 2005 (gmt 0)

10+ Year Member



hi,

Following is my script for retrice date and time (exp: 2005-05-06 12:00:00) from database and display the result.

$result_date = mysql_query("select datetime from update_time where num='1'", $db);
list($datetime) = mysql_fetch_row($result_date, $db);

echo"Date and time= $datetime";

however, I can't get the date and time to be display. Is it any mistake with my script? The date and time was in database with data type of datetime. Any idea?

Blackie

7:50 am on May 6, 2005 (gmt 0)

10+ Year Member



Have you tried running your SQL statement directly in SQL command line to see what result you get in DB?

See nothing wrong with the code.

yllai

8:23 am on May 6, 2005 (gmt 0)

10+ Year Member



I have tried to query it from my DB, it work well.
In my script, I have checked, it can retrive the data but can't be display out.

Any idea?

yllai

8:28 am on May 6, 2005 (gmt 0)

10+ Year Member



Now, I add in 'strtotime' function, it can display the date but not the time.

$result_date = mysql_query("select datetime from update_time where num='1'", $db);
list($datetime) = mysql_fetch_row($result_date, $db);

$last_date = date("Y-m-d H:i:s", strtotime("$datetime"));

echo"<br>Date and time: $last_date";

Any idea?

yllai

8:49 am on May 6, 2005 (gmt 0)

10+ Year Member



would it related to my BD setting or webserver setting?

coopster

1:30 pm on May 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's a data-related issue -- I'll bet 100 to 1 you have a NULL value in your datetime column.

yllai

11:28 pm on May 8, 2005 (gmt 0)

10+ Year Member



No. I have checked that it was a value in the table of my DB.

coopster

2:19 am on May 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I tested the code against a test table in my database successfully ... except when I hit a NULL value -- are you absolutely certain you are looking at the same row you are trying to retrieve? Dump your statement to the browser and run the statement interactively to be sure. Also, are you certain the column is defined correctly?