iceman023 Posted May 10, 2009 Share Posted May 10, 2009 I can't believe its taking me this long to figure out how to go from 2009-05-04 00:00:00 to 05/04/09 I have all the dates that a photo was upload to the database in a field called date. I just want to change the display of the format from the database. Some please help! Pic of the database attached [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/ Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 SELECT DATE_FORMAT(`Date`, '%m/%d/%y') AS `date` FROM tablename Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-830891 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Thank you but where do i put this.. Within the same SELECT statment i already have or do i make a new one. and if so, does it need a while loop... Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831112 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 In your SQL. Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831114 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 IS this what you ment or no... $results = mysql_query(" SELECT * FROM Photos WHERE Published = 'no' AND DATE_FORMAT(`Date`, '%m/%d/%y') AS `Date` FROM Photos ORDER BY ID DESC LIMIT $page, $limit"); while ($data = mysql_fetch_array($results)) { Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831115 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 No. Put it in the SELECT clause. I also assume the column name is Date? Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831117 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Isn't that the select clause??? and yes it is Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831118 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Or is it this one $numresults = mysql_query(" SELECT * FROM Photos WHERE Published = 'no' AND DATE_FORMAT(`Date`, '%m/%d/%y') AS `Date` FROM Photos ORDER BY ID DESC"); // the query. $numrows = mysql_num_rows($numresults); // Number of rows returned from above query. if ($numrows == 0){ echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs. exit();} Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831122 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 --__-- no... SELECT DATE_FORMAT(...) AS `date`, * ... Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831125 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Sorry kinda new to this.. $numresults = mysql_query(" SELECT DATE_FORMAT(`Date`, '%m/%d/%y') AS `Date`, * FROM Photos WHERE Published = 'no' ORDER BY ID DESC"); // the query. $numrows = mysql_num_rows($numresults); // Number of rows returned from above query. if ($numrows == 0){ echo("No results found matching your query - $query"); exit();} Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831128 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Looks fine to me. Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831131 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Doesnt work tho... Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831134 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Is there a SQL error? Can you post the error? Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831137 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in.... in php MyAdmin sql it say.... Error SQL query: SELECT DATE_FORMAT( `Date` , '%m/%d/%y' ) AS `Date` FROM Photos, * FROM Photos WHERE Published = 'no' ORDER BY ID DESC LIMIT 0 , 30 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM Photos WHERE Published = 'no' ORDER BY ID DESC LIMIT 0, 30' at line 2 Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831138 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 Sorry this one... Error SQL query: SELECT DATE_FORMAT( `Date` , '%m/%d/%y' ) AS `Date` , * FROM Photos WHERE Published = 'no' ORDER BY ID DESC LIMIT 0 , 30 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM Photos WHERE Published = 'no' ORDER BY ID DESC LIMIT 0, 30' at line 2 Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831141 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 Oh, you put the asterick first. So like - SELECT *, DATE_FORMAT... Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831142 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 THANK YOU! PERFECT Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831145 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 THANK YOU PERFECT Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831146 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 I hate to be a pain in the ass but I have this SELECT * , DATE_FORMAT( `Date` , '%m %d %y' ) AS `Date` FROM Photos WHERE Published = 'no' ORDER BY ID DESC LIMIT 0 , 30 and the output is "2009-05-04" shouldnt it be.... "05.04.09" IF not how do i get "05.04.09" Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831155 Share on other sites More sharing options...
iceman023 Posted May 10, 2009 Author Share Posted May 10, 2009 NEVERMIND i had to change the second one also.. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831158 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.