navitronic

random amounts of nothing

Helpful Date Helper

A useful php function for presenting a date in a short easy to read format wrapped in an <abbr> tag that displays a longer version of the date.

Your mileage may vary.

function helpful_date($date, $sd_format = 'd/m/y', $ld_format = 'g:ia, l jS F Y', $non_date_return = 'n/a'){

    // send back any non applicable dates.
    // send back any unconvertable dates.
    if( $date == '' || !( $time = strtotime($date) ) ){ return $non_date_return; }

    // adjust time for time difference
    //$time += Config('timediff');

    $long_date  = date($ld_format, $time);
    $short_date = date($sd_format, $time);

    return '<abbr title="'.$long_date.'">'.$short_date.'</abbr>';

}