FUEL CMS User Guide : Version 0.9.3


Extended Date Helper

Extends the CodeIgniter date helper functions. This helper is autoloaded.

This helper is loaded using the following code:

$this->load->helper('date');

The following functions are available:

datetime_now([hms])

Returns a the current time in a yyyy-mm-dd hh:mm:ss format which can be used with MySQL databases. The optional parameter will return the current date without the time if set to FALSE (default is TRUE).

echo datetime_now(); // 2012-05-18 02:36:32 
echo datetime_now(FALSE); // 2012-05-18 02:36:32

is_date_format('date')

Returns a boolean value as to whether the date is in an english (mm/dd/yyyy) or database (yyyy-mm-dd) format.

is_date_format('2010/01/01');
// returns FALSE

is_date_format('2010-01-01');
// returns TRUE

is_date_db_format('date')

Returns a boolean value as to whether the date is in a valid database (yyyy-mm-dd) format.

is_date_format('2010-01-01');
// returns TRUE

is_date_english_format('date')

Returns a boolean value as to whether the date is in a valid 'english' (mm/dd/yyy) format.

is_date_english_format('01/01/2010');
// returns TRUE

english_date('date', [long], [timezone], [delimiter])

Returns a date in 'english' (mm/dd/yyy) format. The long parameter determines whether to include the time or not. The timezone parameter determines whether to include the time or not. The delimiter parameter determines whether to include the time or not.

english_date(time());
// returns 05/18/2012 

english_date_verbose('date')

Returns date in 'verbose' ( Jan. 1, 2010) format.

english_date_verbose(time());
// returns May. 18, 2012

time_verbose('time', [include_seconds])

Returns the time into a verbose format (e.g. 12hrs 10mins 10secs).

time_verbose(time(), TRUE);
//returns 2hrs 36mins 32secs

english_date_to_db_format(date, [hour], [min], [sec], [ampm], [delimiter])

Converts a date from english (e.g. mm/dd/yyyy) to db format (e.g yyyy-mm-dd). The default delimiter parameter is '/'.

english_date_to_db_format('01/01/2010', 12, 10, 0);
// returns 2010-01-01 00:10:00

format_db_date([y], [m], [d], [h], [i], [s])

Formats a date for the database in (yyyy-mm-dd hh:mm:ss) format. If a value is left out, it will return the current date/time value for that slot.

format_db_date(2010, 1, 1, 12, 10, 10);
// returns 2010-01-01 12:10:10

date_range_string(date1, date2)

Creates a date range string (e.g. January 1-10, 2010).

date_range_string('2010-08-01', '2010-08-05');
// returns May 17-18, 2012

pretty_date(timestamp, use_gmt)

Creates a string based on how long from the current time the date provided.

pretty_date(time() - (60 * 60));
// returns 1 hour ago

get_age(bday_ts, [at_time_ts])

Returns an age based on a given date/timestamp. The second parameter is optional and by default will be the current date.

get_age('2000-01-01');
// returns 12