Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

Having brainfart on date algorithm problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Simmons - 19 Jul 2007 17:55 GMT
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
Nicholas Paldino [.NET/C# MVP] - 19 Jul 2007 18:14 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi all,
>
[quoted text clipped - 23 lines]
> Thanks,
> Brian
Brian Simmons - 19 Jul 2007 18:23 GMT
Perfect.  This makes a whole lot more sense than the garbage that was
floating around in my head today.

Thanks for your assistance!

> Brian,
>
[quoted text clipped - 33 lines]
>> Thanks,
>> Brian
ModelBuilder - 19 Jul 2007 18:30 GMT
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!
       }

> Hi all,
>
[quoted text clipped - 23 lines]
> Thanks,
> Brian

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.