Friends, I need to get data from mysql table and display them in which one field is mysql datetime field. Now, i want only time from this datetimefield to be displayed while using echo. i have used mysql_fetch() to collect the data from table and list() to assign the data to variables i want. Then i tried to use strtotime and date() function to get the time as output. But strtotime() is not returning any value where date() is returning some wierd value like this 01/70/01-00:18:31 this is my sample query. $sql= select * from table1; $tmp= mysql_query($sql); while($list($abc, $xyz, $ntime)=mysql_fetch($tmp)) { $lmn = strtotime($ntime); $pqr = date('H:i:s',$lmn); echo "$lmn <br/> $pqr" ; } Now, the result is, <blankspace nothing returned for $lmn > 01/70/01-00:00:00 <"> 01/70/01-00:00:00 <"> 01/70/01-00:18:31 Thanks in advance. Regards, Urs Tom
Can you echo out the values in the date column. Are they in the correct datetime format yyyy-mm-dd hh:mm:ss?
Yah when i echo out without using these functions, i get the date in this format Example: echo "$abc, $xyz, $ntime"; this is giving me a result like this 0000-11-11 01:23:24 1111-11-11 00:00:00 Is there anything wrong with the values that i uploaded into the table?? will the values change the output??
Could you paste one random datetime entry from your mysql? Btw, couldn't you just print out the value?
With your suggestion I tried to change the default values of yr as month date as 1971-11-11 Now i get the out put like this this is orginal date: 1971-11-11 12:34:45 using strtotime for this: 58710885 Using date('H:i:s', strtotime(this date)) : 00:32:51 everything is different. !!!
As i understand, you want to use just time (hours, minutes, seconds). Why don't you use explode function?