Vivid Lust Posted October 20, 2010 Share Posted October 20, 2010 Any ideas how I can turn "2010-10-20 19:10:56" to 20th October 2010, 19:10 Thanks lots guys, Jake Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/ Share on other sites More sharing options...
schilly Posted October 20, 2010 Share Posted October 20, 2010 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124504 Share on other sites More sharing options...
Vivid Lust Posted October 20, 2010 Author Share Posted October 20, 2010 I'm getting Warning: sprintf() [function.sprintf]: Too few arguments in /furanet/sites/l...../web/htdocs/admin/index.php on line 72 Query was empty Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124506 Share on other sites More sharing options...
schilly Posted October 20, 2010 Share Posted October 20, 2010 post your code. with sprintf you need to escape any % signs because it thinks you are inserting a value there so for date_format you need %%b %%d, %%y for the format. Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124513 Share on other sites More sharing options...
Vivid Lust Posted October 20, 2010 Author Share Posted October 20, 2010 $query_Recordset2 = sprintf('SELECT DATE_FORMAT(inicio,"%H:%i") FROM juegos_sesiones WHERE usuarioID = '.$lastOnline[$counter].' ORDER BY sesionID DESC LIMIT 1'); Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124516 Share on other sites More sharing options...
schilly Posted October 20, 2010 Share Posted October 20, 2010 why are you using sprintf without inserting any values into it? Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124530 Share on other sites More sharing options...
Vander Posted October 20, 2010 Share Posted October 20, 2010 I would like to suggest that if possible, you convert to using INT(11) feilds and use UNIX_TIMESTAMP, a UNIX timestamp can be changed into any format you want using the PHP date() function. Yes, the days of UNIX timestamps are limited, but that's nothing to worry about until like 2038 or something, so there's plenty of time, and even by then there will probably be new languages and your site would be long gone down the infinate shitter of the internet. XD But aye, I hope this helps, Alan. Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124532 Share on other sites More sharing options...
schilly Posted October 20, 2010 Share Posted October 20, 2010 Why would you use PHP to do date conversion when MySQL can do it for you? Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124536 Share on other sites More sharing options...
Vander Posted October 20, 2010 Share Posted October 20, 2010 Why would you use PHP to do date conversion when MySQL can do it for you? Umm... Well when I'm working with MySQL, I tend to use PHP as the front end, shit just seems easier to me? Everyone has their own wee methods of coding and shit. XD Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124541 Share on other sites More sharing options...
PFMaBiSmAd Posted October 20, 2010 Share Posted October 20, 2010 Doing the conversion in the query is at least 8x faster than doing it using php code. Kind of important if you have a lot of data being retrieved or you need your site to to handle a large number of visitors. Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124546 Share on other sites More sharing options...
schilly Posted October 20, 2010 Share Posted October 20, 2010 Umm... Well when I'm working with MySQL, I tend to use PHP as the front end, shit just seems easier to me? Everyone has their own wee methods of coding and shit. XD I use to think that until I found out about the MySQL Date Time Functions: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/216395-formatting-mysql-timestamp/#findComment-1124550 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.