Xtremer360 Posted September 12, 2012 Share Posted September 12, 2012 I'm trying to turn 2012-09-12 14:00:00 into September 12, 2012 2:00 pm using the php date function but I'm getting a A non well formed numeric value encountered error and not sure if I just didn't apply the function correctly or am missing something. Any ideas? date('F d, Y h:i:s a', $row->news_article_posting_date) Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/ Share on other sites More sharing options...
lemmin Posted September 12, 2012 Share Posted September 12, 2012 date() accepts an integer in the form of a timestamp as the second parameter. You are probably passing it a string: "2012-09-12 14:00:00." Try using strtotime(): date('F d, Y h:i:s a', strtotime($row->news_article_posting_date)) http://us2.php.net/manual/en/function.date.php http://us2.php.net/manual/en/function.strtotime.php Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377410 Share on other sites More sharing options...
Pikachu2000 Posted September 12, 2012 Share Posted September 12, 2012 It would make more sense to do this in the query itself with MySQL's DATE_FORMAT() function. Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377411 Share on other sites More sharing options...
Xtremer360 Posted September 12, 2012 Author Share Posted September 12, 2012 It would make more sense to do this in the query itself with MySQL's DATE_FORMAT() function. What's the advantage? Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377413 Share on other sites More sharing options...
Pikachu2000 Posted September 12, 2012 Share Posted September 12, 2012 Speed and efficiency. The php date/time functions are very slow relative to the MySQL functions. Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377415 Share on other sites More sharing options...
Xtremer360 Posted September 12, 2012 Author Share Posted September 12, 2012 Well I'm working it into my query but I'm getitng a Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/xtremer/public_html/kowmanager/app/models/news_model.php on line 31 $this->db->select("DATE_FORMAT(".$this->master_model->news_articles_table.".news_article_posting_date, '%M %D, %Y') AS news_article_posting_date", FALSE); $this->db->select("CONCAT_WS(' ', ".$this->master_model->users_table.".first_name, ".$this->master_model->users_table.".last_name) AS author", FALSE); Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377427 Share on other sites More sharing options...
lemmin Posted September 12, 2012 Share Posted September 12, 2012 I don't see a syntax error there. Can you post more code from around it and note which is line 31? Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377432 Share on other sites More sharing options...
Xtremer360 Posted September 13, 2012 Author Share Posted September 13, 2012 I've triggered it to be those two lines. Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377472 Share on other sites More sharing options...
Jessica Posted September 13, 2012 Share Posted September 13, 2012 Post lines 30-32. Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377475 Share on other sites More sharing options...
booxvid Posted September 13, 2012 Share Posted September 13, 2012 It would make more sense to do this in the query itself with MySQL's DATE_FORMAT() function. Agree ^ Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377612 Share on other sites More sharing options...
PFMaBiSmAd Posted September 14, 2012 Share Posted September 14, 2012 I'm going to assume that you solved the php syntax error in this thread, because you started another thread for a sql syntax error you made trying to 'fix' the php error. Quote Link to comment https://forums.phpfreaks.com/topic/268308-date-format/#findComment-1377839 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.