Skip to content

Instantly share code, notes, and snippets.

@adhipg
Created September 12, 2011 11:10
Show Gist options
  • Save adhipg/1211031 to your computer and use it in GitHub Desktop.
Save adhipg/1211031 to your computer and use it in GitHub Desktop.
Format a set of dates (timestamps) into a format like 1, 2, 3 Jan, 13 Feb, 15 Mar 2011
<?php
function formatDates( $dates ) {
$output = '';
$month = '';
$year = '';
sort( $dates, SORT_NUMERIC );
foreach ( $dates as $date ) {
$date = floatval( $date );
if( date(' M, ' , $date) != $month ) {
$output = rtrim( $output, ', ' ) . $month;
$month = date( ' M, ' , $date );
}
if( date(' Y, ', $date) != $year ) {
$output = rtrim( $output, ', ' ) . $year;
$year = date( ' Y, ' , $date );
}
$output .= date('j, ', $date );
}
$output = rtrim( $output, ', ') . rtrim( $month, ', ' ) . rtrim( $year, ', ' );
return $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment