nicolanicola Posted April 9, 2010 Share Posted April 9, 2010 I am extremely new to this, so please bear with me if I don't make sense. In a php script, I add a datestamp to a field by using the now() function. I am retrieving this field now from db, I have successfuly managed to get the date and convert it - select DATE_FORMAT(date,'%d-%m-%Y') as postedDate. But I can't get the time at all. Can someone please help? I've tried using convert but I think I'm doing it wrong, because my php code just exits and the html then continues, after the following select statement. If I take convert out it works, so I figure something is wrong with the convert statement. mysql_query("SELECT asset_id, name, email, website ,comment, CONVERT(varchar(10), date, 108) as theTime, DATE_FORMAT(date,'%d-%m-%Y') as postedDate FROM Comment WHERE asset_id='lbi-type' ORDER BY date", $connection); Quote Link to comment https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/ Share on other sites More sharing options...
spfoonnewb Posted April 9, 2010 Share Posted April 9, 2010 Date and time are combined in a datetime field. mysql_query("SELECT asset_id, name, email, website ,comment, DATE_FORMAT(date,'%h:%i:%s') as theTime, DATE_FORMAT(date,'%d-%m-%Y') as postedDate FROM Comment WHERE asset_id='lbi-type' ORDER BY date", $connection); Quote Link to comment https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/#findComment-1039245 Share on other sites More sharing options...
nicolanicola Posted April 9, 2010 Author Share Posted April 9, 2010 Thank you, you've just saved me hours of work Spent about an hour trying to get convert to work. Quote Link to comment https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/#findComment-1039246 Share on other sites More sharing options...
nicolanicola Posted April 9, 2010 Author Share Posted April 9, 2010 Incidentally, my order by clause isn't working. My comments are displayed from oldest to newest. Am I using it correctly? Quote Link to comment https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/#findComment-1039248 Share on other sites More sharing options...
andrewgauger Posted April 9, 2010 Share Posted April 9, 2010 "order by date desc" to reverse order. http://dev.mysql.com/doc/refman/5.0/en/select.html Quote Link to comment https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/#findComment-1039287 Share on other sites More sharing options...
nicolanicola Posted April 9, 2010 Author Share Posted April 9, 2010 thanks Quote Link to comment https://forums.phpfreaks.com/topic/198064-am-i-using-convert-wrong/#findComment-1039372 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.