/ Published in: PHP
Takes one or two PHP timestamps, and returns a somewhat humanized string representing the date range
* Jun 7th, 2013
* Jun 7th-11th, 2013
* Jun 7th-Jul 3rd, 2013
* Jun 7th, 2013-Jan 1st, 2013
* Jun 7th, 2013
* Jun 7th-11th, 2013
* Jun 7th-Jul 3rd, 2013
* Jun 7th, 2013-Jan 1st, 2013
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Takes one or two TIMESTAMPs, and an optional formatting array of the form ($year, $month, $day), * and returns a date that is appropriate to the situation * @param int $start * @param int $end * @param array $fmt * @return boolean|string */ function _pj_pretty_date( $start, $end = NULL, $fmt = NULL ) { return false; } // default formatting } } // close enough } // ok, so $end != $start // let's look at the YMD individually, and make a pretty string ); // init dates $start_date = ''; $end_date = ''; $start_date .= $dates['s_month']; if( $dates['s_month'] != $dates['e_month'] ) { $end_date .= $dates['e_month']; } $start_date .= ' '. $dates['s_day']; if( $dates['s_day'] != $dates['e_day'] || $dates['s_month'] != $dates['e_month'] ) { $end_date .= ' ' . $dates['e_day']; } if( $dates['s_year'] != $dates['e_year'] ) { $start_date .= ', ' . $dates['s_year']; if( $dates['s_month'] == $dates['e_month'] ) { if( $dates['s_day'] == $dates['e_day'] ) { // same day, same month, different year $end_date = ' ' . $dates['e_day'] . $end_date; } // same month, but a different year $end_date = $dates['e_month'] . $end_date; } } $end_date .= ', ' . $dates['e_year']; return $complete_date; }