Using PHP I'd like to take two unix time stamps and display the date as such if they span different months:
December 6th 2013 - January 8th, 2014
but to show date ranges like this:
December 6th - 8th, 2013
when they don't span across a month or year.
My current code is below (obviously this doesn't do what I'm looking for). Hoping someone else has worked this out or it's hidden somewhere in date() and I just don't know about it.
<?php
// Date
$startDate = get_post_meta( get_the_ID(), 'wvc_session_start_timestamp', true );
$startDatePretty = date( 'F jS Y', $startDate);
$endDate = get_post_meta( get_the_ID(), 'wvc_session_end_timestamp', true );
$endDatePretty = date( 'F jS Y', $endDate);
$html .= '<div class="event-date">';
// check if the custom field has a value
if( ! empty( $startDate ) ) {
$html .= $startDatePretty;
}
// check if the custom field has a value
if( ! empty( $endDate ) ) {
if( $endDatePretty != $startDatePretty ) {
$html .= ' - ' . $endDatePretty;
}
}