Having brainfart on date algorithm problem

  • Thread starter Thread starter Brian Simmons
  • Start date Start date
B

Brian Simmons

Hi all,

I'm just having one of those days where seemingly easy problems are giving
me a devil of a time.

Here's the scenario:
Company's fiscal year runs from 10/1/YY -> 9/30/(YY+1), i.e. 10/1/2006 ->
9/30/2007

Users are required to enter a FromDate and ToDate for services needed.
The dilemna: The FromDate and ToDate cannot span a fiscal year.

Good dates (arbitrarily picked to give some examples):
10/1/06 -> 11/1/06
10/1/06 -> 2/1/07
10/1/06 -> 9/30/07
3/1/07 -> 9/30/07

Bad dates:
10/1/06 -> 10/1/07
9/30/06 -> 11/1/07
9/1/07 -> 10/5/07

Anyone game for helping me out?

Thanks,
Brian
 
Brian,

First, figure out the minimum of the two dates. Then, calculate the
start of the next fiscal year based on that minimum date. Basically, it is
10/1/xxxx where xxxx is the year of the minimum date. You will have to add
a year if the date is greater than or equal to 10/1/xxxx.

Then, take the other date. If it is greater than or equal to the
calculated date, then it is invalid.
 
Perfect. This makes a whole lot more sense than the garbage that was
floating around in my head today.

Thanks for your assistance!

Nicholas Paldino said:
Brian,

First, figure out the minimum of the two dates. Then, calculate the
start of the next fiscal year based on that minimum date. Basically, it
is 10/1/xxxx where xxxx is the year of the minimum date. You will have to
add a year if the date is greater than or equal to 10/1/xxxx.

Then, take the other date. If it is greater than or equal to the
calculated date, then it is invalid.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Brian Simmons said:
Hi all,

I'm just having one of those days where seemingly easy problems are
giving me a devil of a time.

Here's the scenario:
Company's fiscal year runs from 10/1/YY -> 9/30/(YY+1), i.e. 10/1/2006 ->
9/30/2007

Users are required to enter a FromDate and ToDate for services needed.
The dilemna: The FromDate and ToDate cannot span a fiscal year.

Good dates (arbitrarily picked to give some examples):
10/1/06 -> 11/1/06
10/1/06 -> 2/1/07
10/1/06 -> 9/30/07
3/1/07 -> 9/30/07

Bad dates:
10/1/06 -> 10/1/07
9/30/06 -> 11/1/07
9/1/07 -> 10/5/07

Anyone game for helping me out?

Thanks,
Brian
 
static int FiscalYear(DateTime d)
{
int y = d.Year;
if (d.Month > 9) ++y;

return y;
}

static voic main()
{
if (FiscalYear(dtFromDate) == FiscalYear(dtToDate)) //
something good!
}
 
Back
Top