Checking if parsed date is within a date 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
3:03 UTC
Read the original article
Hit count: 245
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.
© Stack Overflow or respective owner