I have a date string formatted as March 8 - 10
where the year is not provided, but based on the current day of the calendar year, this would be dates in March of the next year.
What is best approach to provide the accurate year when a date given similar to the above is past Dec 31?
Thinking something like below using $sdate > $now
however this would add +1 year to any date greater than now and not consider Dec 31 as the end of current year.
$dates = trim('March 8 - 10');
$now = date("Y-m-d",strtotime("now"));
if (strpos($dates,'-') !== false) {
$sdate = trim(substr($dates, 0, strpos($dates, '-')));
if ($sdate > $now) {
$sdate = strtotime("+1 year", strtotime($sdate));
$sdate = date("Y-m-d", $sdate);
}
$month = substr($sdate, 0, strpos($sdate, ' '));
$edate = $month.substr($dates, -2, strpos($dates, '-'));
$edate = date("Y-m-d",strtotime($edate));
}