Created
June 21, 2012 16:26
-
-
Save mattboon/2966839 to your computer and use it in GitHub Desktop.
WordPress - Get start and end date and format them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// event date | |
$dstart = get_field('event_date_start'); | |
$dend = get_field('event_date_end'); | |
if (!$dend) { | |
$dend = $dstart; | |
} | |
$start_year = date("o",strtotime($dstart)); | |
$end_year = date("o",strtotime($dend)); | |
// pretty date formats | |
$pretty_dstart = date("jS F o",strtotime($dstart)); | |
$pretty_dstart_noyear = date("jS F",strtotime($dstart)); | |
$pretty_dend = date("jS F o",strtotime($dend)); | |
// output | |
if ($start_year==$end_year&&$dstart!=$dend) { | |
$event_start = $pretty_dstart_noyear; | |
} | |
else { | |
$event_start = $pretty_dstart; | |
} | |
if ($dstart!=$dend) { | |
$event_end = '– ' . $pretty_dend . ''; | |
} | |
?> | |
<dl> | |
<dt>Event date</dt> | |
<dd><?= $mtg_start; ?> <?= $mtg_end; ?></dd> | |
</dl> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment