471,605 Members | 1,623 Online

# 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.