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] 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 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... 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. 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)) { 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? 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 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();} 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`, * ... 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();} 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. 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... 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? 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 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 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... 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 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 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" 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! Link to comment https://forums.phpfreaks.com/topic/157564-solved-time-format/#findComment-831158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.