nice_date()

nice_date([$bad_date = ''[, $format = FALSE]])

Parameters:
  • $bad_date (int) – The terribly formatted date-like string
  • $format (string) – Date format to return (same as PHP’s date() function)
Returns:

Formatted date

Return type:

string

This function can take a number poorly-formed date formats and convert them into something useful. It also accepts well-formed dates.

The function will return a UNIX timestamp by default. You can, optionally, pass a format string (the same type as the PHP date() function accepts) as the second parameter.

Example:

$bad_date = '199605';
// Should Produce: 1996-05-01
$better_date = nice_date($bad_date, 'Y-m-d');

$bad_date = '9-11-2001';
// Should Produce: 2001-09-11
$better_date = nice_date($bad_date, 'Y-m-d');
doc_CodeIgniter
2016-10-15 16:32:31
Comments
Leave a Comment

Please login to continue.