every 2 week function

G

Guest

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
 
B

Baileys

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top