Welcome Guest, Not a member yet? Register   Sign In
Parsing datetime from MySQL
#9

[eluser]mddd[/eluser]
When you are only working with one single record, the performance issue will be probably not be noticable. So you don't have to change it for the sake of performance. But I think it is not the best way to take a date as a string from Mysql only to have Php turn it back into a date (with the strtotime() command) and then turning that back into a readable date again (with the date() command). That is like taking a detour. You can get the formatting straight from Myqsl using the Date_format() function in Mysql. It works just like the date() command in Php.
Code:
// in model
$this->db->select("*, date_format(date, '%M/%d/%Y') as human_date, date_format(date, '%H:%i:%s') as human_time", false);

// in view
<h2>&lt;?php echo $title; ?&gt;</h2>
<p>&lt;?php echo $human_date; ?&gt;</p>
<div>&lt;?php echo $body; ?&gt;</div>
<p>&lt;?php echo $human_time; ?&gt;</p>


Messages In This Thread
Parsing datetime from MySQL - by El Forum - 04-11-2010, 06:15 PM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 12:46 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 12:55 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 01:02 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 07:23 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 07:30 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 07:34 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 10:01 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 10:19 AM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 04:59 PM
Parsing datetime from MySQL - by El Forum - 04-12-2010, 05:12 PM
Parsing datetime from MySQL - by El Forum - 04-13-2010, 12:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB