This one's not correct. If target is 0101, and date one is 1122 and date2 is 0315, that will be issued as a not between, when it is. Also, don't forget that:
0101 = 65
1122 = 1122
0315 = 205
Which could alter your numbers logic by a lot.
The idea is correct, but the application is wrong since it doesn't account for years rolling past even when we don't accommodate the year.
I can think of a few ways that'd deal with this, but dateTime is probably the easiest:
function isDateBetween(DateTime $dtTarget, DateTime $dtStart, DateTime $dtEnd)
$bResult = false;
if ($dtStart > $dtEnd)
// We'll be checking "outside" of the range instead of inside.
$bResult = !($dtTarget > $dtEnd && $dtTarget < $dtStart);
$bResult = $dtTarget >= $dtStart && $dtTarget <= $dtEnd;
I haven't tested this, but that *seems* to work okay in my head. You'd use it simply as:
$dtStart = new DateTime('November 11');
$dtEnd = new DateTime('March 3');
$dtTarget = new DateTime('February 12');
printf('%s is between %s and %s? %d' . PHP_EOL,
isDateBetween($dtTarget, $dtStart, $dtEnd));
For example. Note there are no years here, but the implicit year is this year. If you add years, it will override the implicit which can constrain the window or open it wider. So if you were to base this on a time provided with a year, you'd need to strip the year out (or use mktime and then wrap that in a dateTime).
You'd need to test that out quite a bit, especially with some wider and narrower windows. Best I can figure in my head here is that on a year by year basis this won't be a problem; the endtime should be good even if you provide years since a year override would still fit in to the comparisons.