Checking if parsed date is within a date range
- by Brett Powell
So I am using a scripting language with c++-like syntax, and I am trying to think of the best way to check if a date is within range. The problem I am running into is that if the current day is in a new month, the check is failing.
Here is what my code looks like:
if(iMonth >= iStartMonth && iMonth <= iEndMonth)
{
if(iDay >= iStartDay && iDay <= iEndDay)
{
if(iYear >= iStartYear && iYear <= iEndYear)
{
bEnabled = true;
return;
When I have something like this:
Start date: 3 27 2010
End Date: 4 15 2010
Current Date: 3 31 2010
The day check fails because if (iDay <= iEndDay) does not pass. The scripting language doesn't have a lot of time related functions, and I can't compare timestamps because I'm allowing users to put like "03:27:2010" and "04:15:2010" as start/end dates in a config file. I'm assuming I am just not thinking straight and missing an easy fix.