471,605 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

every 2 week function

There are probably a dozen really obnoxious ways to solve this :
But I am trusting someone has a better idea than mine.

The method calls below will tell me by the result= 0 if my program
has reached another 2 week cycle. But once the year rolls over..
- Seems like I need to get the days not from year but the days
from the beginning of time...( although I am not sure how to get that ...)
or resort to some other roll over techniques.
int update = 0;
int iresult;

DateTime theday = DateTime.Now;
int dayOfYear = theday.DayOfYear;

DateTime SeedDate = Convert.ToDateTime("1/23/06");
int seedDayOfYear = SeedDate.DayOfYear;

update = Math.DivRem(dayOfYear-seedDayOfYear, 14, out iresult);

Thanks
--
Andrew
Feb 7 '06 #1
2 1443
You can get the difference (number of days) between two datetimes by
subtracting them and reading the "TotalDays" property from the resulting
TimeSpan, something like:

DateTime now = DateTime.Now;
DateTime seed = Convert.ToDateTime("2006/01/01");

TimeSpan diff = now - seed;
int result = diff.TotalDays % 14;

hth,
Baileys

andrewcw wrote:
There are probably a dozen really obnoxious ways to solve this :
But I am trusting someone has a better idea than mine.

The method calls below will tell me by the result= 0 if my program
has reached another 2 week cycle. But once the year rolls over..
- Seems like I need to get the days not from year but the days
from the beginning of time...( although I am not sure how to get that ...)
or resort to some other roll over techniques.
int update = 0;
int iresult;

DateTime theday = DateTime.Now;
int dayOfYear = theday.DayOfYear;

DateTime SeedDate = Convert.ToDateTime("1/23/06");
int seedDayOfYear = SeedDate.DayOfYear;

update = Math.DivRem(dayOfYear-seedDayOfYear, 14, out iresult);

Thanks

Feb 7 '06 #2
Thanks that's exactly what I needed to build my function
--
Andrew
"andrewcw" wrote:
There are probably a dozen really obnoxious ways to solve this :
But I am trusting someone has a better idea than mine.

The method calls below will tell me by the result= 0 if my program
has reached another 2 week cycle. But once the year rolls over..
- Seems like I need to get the days not from year but the days
from the beginning of time...( although I am not sure how to get that ...)
or resort to some other roll over techniques.
int update = 0;
int iresult;

DateTime theday = DateTime.Now;
int dayOfYear = theday.DayOfYear;

DateTime SeedDate = Convert.ToDateTime("1/23/06");
int seedDayOfYear = SeedDate.DayOfYear;

update = Math.DivRem(dayOfYear-seedDayOfYear, 14, out iresult);

Thanks
--
Andrew

Feb 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by androtech | last post: by
7 posts views Thread by Shuffs | last post: by
reply views Thread by Lee Harr | last post: by
18 posts views Thread by Jen | last post: by
6 posts views Thread by aarklon | last post: by
10 posts views Thread by Jim | last post: by
3 posts views Thread by sbaird | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

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.