diasansley Posted February 25, 2011 Share Posted February 25, 2011 hey guys the date stored in mysql is yyyy-mm-dd i need to convert it to do a string compare i have used the following $query = "SELECT * FROM booking where id=$sel"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $num1=$row['no_rooms']; $from1=$row['from']; $to=$row['to']; $sel1=$row['room_type']; $date = date('d-m-y', strtotime($from1)); } echo "$date"; it prints 01-01-70 can any1 tell me where is the error? thanks Quote Link to comment https://forums.phpfreaks.com/topic/228795-date-conversion-from-mysql/ Share on other sites More sharing options...
bh Posted February 25, 2011 Share Posted February 25, 2011 Hi, becouse you use mysql_fetch_array your $row value has numerical indexes, its not an associative array. So you have $row[0], $row[1] but not $row['to'], $row['from'] use instead mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/228795-date-conversion-from-mysql/#findComment-1179509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.