Checking if Date is within Range

Posted by Brett Powell on Stack Overflow See other posts from Stack Overflow or by Brett Powell
Published on 2010-04-01T02:47:33Z Indexed on 2010/04/01 2:53 UTC
Read the original article Hit count: 244

Filed under:
|

So I am using a scripting language with c++ syntax, and 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...

(Pulled in from cfg file specified by client)
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 cant compare timestamps because im allowing users to put like "03:27:2010" and "04:15:2010" as start/end dates in a config file. Im assuming I am just not thinking straight and missing an easy fix.

© Stack Overflow or respective owner

Related posts about c++

Related posts about scripting