473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Having brainfart on date algorithm problem

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
Jul 19 '07 #1
3 1508
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]
- mv*@spam.guard.caspershouse.com

"Brian Simmons" <ce******@newsgroup.nospamwrote in message
news:ee**************@TK2MSFTNGP05.phx.gbl...
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

Jul 19 '07 #2
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP05.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Brian Simmons" <ce******@newsgroup.nospamwrote in message
news:ee**************@TK2MSFTNGP05.phx.gbl...
>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


Jul 19 '07 #3
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!
}

"Brian Simmons" wrote:
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
Jul 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: scottelkin | last post by:
I am trying to find all affiliates that have more commissions from this week to the prior week. The problem is in the having part where "aff2.affiliateid = aff.affiliateid". SQL Server just...
8
by: Dennis M. Marks | last post by:
What is the maximum valid date range for the date(yyyy,mm,dd) function. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/ Replace domain.invalid with dcsi.net -----= Posted via...
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
5
by: Jonathan Crawford | last post by:
Hi I am niew to pho and am having trouble with dates. I can format a date ok so $today=date('d M Y' ) gives me 2 Nov 2005 $dateval is a mysql date
4
by: p175 | last post by:
People, I'm trying to figure if SQL is able find sequences of transactions that occur over say a four day period. I have a table that contains a txn id and a date. Each transaction might...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
4
by: The Spoon | last post by:
I am looking for functions that can be used to automatically update the system date and time on an NT based system, resulting from manually entered date and time values input by an operator via a...
4
by: Ekong, Samuel Akpan | last post by:
Hi, I am parsing a binary file and intend to read a date(not time) field encoded thus: 0xA1290B(little-endian). Now I know the date to be 12/04/2003 but just cannot get any of the known datetime...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.