Formatting output of datetime MySQL value

I wanted to give a new output for those ugly looking datetime values in MySQL, which we get by using NOW() function in INSERT.

Why? because it pretty darn ugly, unpresentable and robot like.

Ok ok, maybe that’s description overkill for datetime, but how would you like this “2010-02-14 11:12:58″ to look like this “February 14, 2010″.

Pretty readable that the later huh.

Ok enough blah blah, here is my function, feel free to abuse it. :)

function Format_Date($date){
	$mos=array('01'=>January,'02'=>February,'03'=>March, '04'=>April, '05'=>May, '06'=>June, '07'=>July, '08'=>August, '09'=>September, '10'=>October, '11'=>Novermber, '12'=>December);
	$d = explode(" ",$date);
	$n = explode("-",$d[0]);
	return $mos[$n[1]].' '.$n[2].', '.$n[0].' '.$d[1];
}

To use this function:

$query=mysql_query("SELECT datetime FROM table"); //2010-02-14 12:11:03
while($row=mysql_fetch_assoc($query)){
echo Format_Date($row[datetime]);//February 14, 2010
}

Easy right? fell free to post your customizatios :)

Tags: , , ,

3 Responses to “Formatting output of datetime MySQL value”

  1. thank you !! extremely useful publish!

  2. admin says:

    Your welcome :)

  3. rico says:

    very useful thanks regin

Leave a Reply