- substr: documentation ( source)
- trim: documentation ( source)
- strrpos: documentation ( source)
<?php
$in = trim('November 8 - 10');
$now = new DateTime(); // Defaults to now
$start = DateTime::createFromFormat('F j+', $in); // Parse month and day, ignore the rest
if ($now > $start) {
$start->modify("next year");
}
$end = clone $start;
$end->setDate(
$end->format('Y'), // $start year
$end->format('n'), // $start month
substr($in, strrpos($in, ' ') + 1) // trailing bit of $in for day
);
echo $start->format("Y-m-d"), "\n";
echo $end->format("Y-m-d");