-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Date Helper
I added my own little function to CI's "Date" helper file that assists with quick formatting of date strings, particularly those returned from a db table. Feel free to use it, modify it, add your own format strings, whatever.
Simple usage: include the date helper file as you normally would, then pass a date to setDate() along with a format (currently 'short', 'long,' or 'notime'):
[code] $this->include->helper('date');
$date = "2009-06-15": $shortdate = setDate($date, 'short'); # returns '06 / 15 / 2009 - 9:32AM' $longdate = setDate($date, 'long'); # returns 'June 15, 2009 - 9:32AM' $notime = setDate($date, 'notime'); # returns '06 / 15 / 2009' [/code]
Here's the snippet:
[code] /**
-
More simplified date stuff
-
by Bob Sawyer / Pixels and Code
-
@access public
-
@param string
-
@param integer
-
@return integer */
if ( ! function_exists('setDate')) { function setDate($datestr = '',$format = 'long') { if ($datestr == '') return '--';$time = strtotime($datestr); switch ($format) { case 'short': $fmt = 'm / d / Y - g:iA'; break; case 'long': $fmt = 'F j, Y - g:iA'; break; case 'notime': $fmt = 'm / d / Y'; break; } $newdate = date($fmt,$time); return $newdate;
} } [/code]