473,395 Members | 1,797 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,395 software developers and data experts.

Figuring the day

We figure budgets in 26 14 days periods in a year. I
currently can take a date and calculate which of those 26
periods that date falls in. Now I have to figure out
what is beginning and ending date of that period.

Here is how the period is figured:
public int GetBudgetPeriod(DateTime d)
{
int days = d.DayOfYear;
int period = (days-1) / 14; // -1 to make sure the
14'th day is in period 1
return period+1; // add 1 to make
periods start at 1
}

Nothing is working for me on figuring out the beginning
and ending dates of the period.

Any suggestions?

Thanks.
Nov 15 '05 #1
1 1030
Darin,

That is easy enough. If you have the beginning of the year in the date
then you can do the following.

Once you have the period, you can take the beginning of the year, and
add 14 days for each period (minus one). So, you would have this:

// Get the days from the beginning of the year that the period falls in.
int pintStartDaysToAdd = (pintPeriods - 1) * 14;

This would give you 0 for the first period, 1 for the second, and so on,
and so on.

Then, to get the end, you would just add 14 to the result to get the end
of the period and subtract one:

// Add 14 days to the beginning of the period.
int pintEndDaysToAdd = pintStartDaysToAdd + 13;

Now, add both of those values to the beginning of the year to get the
beginning and end date (using the DateTime and TimeSpan structures).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Darin Browne" <db@usa.com> wrote in message
news:0b****************************@phx.gbl...
We figure budgets in 26 14 days periods in a year. I
currently can take a date and calculate which of those 26
periods that date falls in. Now I have to figure out
what is beginning and ending date of that period.

Here is how the period is figured:
public int GetBudgetPeriod(DateTime d)
{
int days = d.DayOfYear;
int period = (days-1) / 14; // -1 to make sure the
14'th day is in period 1
return period+1; // add 1 to make
periods start at 1
}

Nothing is working for me on figuring out the beginning
and ending dates of the period.

Any suggestions?

Thanks.

Nov 15 '05 #2

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

Similar topics

6
by: codecraig | last post by:
i want to the number of bytes in a string... is, len(x) accurate? so, x = "hi" len(x) == 2 ....so that means two bytes? thanks
8
by: Nathan Pinno | last post by:
Hi all, I need help figuring out how to fix my code. I'm using Python 2.2.3, and it keeps telling me invalid syntax in the if name == "Nathan" line. Here is the code if you need it. #This...
0
by: Sumaira Maqsood Ali | last post by:
following is taken from postgresql-7.3.2/src/backend/storage/lmgr/readme: "If we are setting a table level lock both the blockId and tupleId (in an item pointer this is called the position) are...
0
by: chrisc22 | last post by:
Hi, I have a problem that goes something like this: I want to determine the minimum height that a label control can have, given an arbitrarily long string, that will make all text visible, with 0...
1
by: Voss | last post by:
Here's what's going on. I have a 2 computers (x & y) running SQL2000. I backed up a copy a DB from x and restored it on y. I have a Stored proc that runs in under 2 seconds on both x & y when...
2
by: Roberto Leibman | last post by:
I haven't been able to figure this out, or find any resource for this. I'd like to be able to know, in javascript, if the media that's rendering is screen or print. I have no nefarious purpose...
9
by: Matthias Kaeppler | last post by:
Hi, I'm using phpWebSite to build my website and I want it to be standard conforming. However, the CSS validator always outputs an error: "Please, validate your XML document first! The...
0
by: you | last post by:
Hiya! I am having some trouble figuring out how to use reflection in a specific way and was wondering if anyone could help. I hope that I can explain what I am trying to do clearly so bear with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.