473,320 Members | 2,133 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,320 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 1495
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
0
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer)...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
18
by: Jen | last post by:
Is it possible (how) to display a new record every week (or day) from a recordset?
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
10
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the...
3
by: sbaird | last post by:
Aloha from Hawaii, I'm beating my head on the wall here. I have a recruiting contact managment database I'm trying to create. Managers (there ar 14 of them) have to make a certain number of...
4
by: Vince | last post by:
Given a week Number, how do I calculate the date that for the Monday of that week?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.