I have an ASP.Net calendar feature which allows users to add events and
configure whether or not they repeat at various frequencies (i.e, daily,
weekly, monthly, Sat/Sun, etc.). What I'm looking for is some C# code that
will calculate a date of "Every Other Week" based on a starting date and
ending date.
Example: If a user enters an event dated October 3, 2005 and would like it
to repeat every other week until October 31, 2005, the code will return the
following dates:
October 3, 2005
October 17, 2005
October 31, 2005
Any help would be greatly appreciated.
Rob 4 5898
I think its as simple as adding number of days to the datetime type as:
DateTime dt = new DateTime(2005, 10, 3);
dt=dt.AddDays(14);
now dt has 17th oct. You keep on adding days like that until the the end
date comes, like in a loop.
Hope that helps.
Ab. http://joehacker.blogspot.com
"Rob Johnson" <rj**********@comcast.net> wrote in message
news:nN********************@comcast.com... I have an ASP.Net calendar feature which allows users to add events and configure whether or not they repeat at various frequencies (i.e, daily, weekly, monthly, Sat/Sun, etc.). What I'm looking for is some C# code
that will calculate a date of "Every Other Week" based on a starting date and ending date.
Example: If a user enters an event dated October 3, 2005 and would like it to repeat every other week until October 31, 2005, the code will return
the following dates:
October 3, 2005 October 17, 2005 October 31, 2005
Any help would be greatly appreciated.
Rob
It's a bit more complex than that Ab. In order to determine how many dates
there are representing "Every other Week" starting on October 3, 2005 and
ending on October 31, 2005, you first have to figure out how many entries
there should be. In this case, there should be 3. A "for loop" is required
to loop through Oct 3 to Oct 31 and return either the number of days or
weeks. Example, the code below will insert the correct number of entries for
an event that repeated every day from Oct 3 to Oct 31 (intNumberofDays is
determined using TimeSpan):
if (EventFrequency == "Day")
{
for(int i = 0; i <= intNumberofDays; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDateTime, " +
"EventEndDateTime) VALUES " +
"('" + dtEventStartDateTime.AddDays(i) + "', " +
"'" + dtEventEndDateTime.AddDays(i) + "') ";
objConnection = new SqlConnection(dbPath);
objCommand = new SqlCommand(strInsert,objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close();
}
}
The problem I'm running into is substituting "intNumberofDays" with
"intNumberofWeeks" will return 5 weeks, where I really need it to return 3
weeks. "i" will then be 3 which I can plug into a revised SQL insert
statement and use "dtEventStartDateTime.AddWeeks(i)" to populate my database
with the 3 dates representing "Every Other Week" (Oct 3, Oct, 17, Oct 31).
Simply subtracting 2 weeks won't work since the duration of events entered
by users can change from entry to entry.
"Abubakar" <ab*******@gmail.com> wrote in message
news:Ot**************@TK2MSFTNGP12.phx.gbl... I think its as simple as adding number of days to the datetime type as:
DateTime dt = new DateTime(2005, 10, 3); dt=dt.AddDays(14);
now dt has 17th oct. You keep on adding days like that until the the end date comes, like in a loop.
Hope that helps.
Ab. http://joehacker.blogspot.com
"Rob Johnson" <rj**********@comcast.net> wrote in message news:nN********************@comcast.com... I have an ASP.Net calendar feature which allows users to add events and configure whether or not they repeat at various frequencies (i.e, daily, weekly, monthly, Sat/Sun, etc.). What I'm looking for is some C# code that will calculate a date of "Every Other Week" based on a starting date and ending date.
Example: If a user enters an event dated October 3, 2005 and would like
it to repeat every other week until October 31, 2005, the code will return the following dates:
October 3, 2005 October 17, 2005 October 31, 2005
Any help would be greatly appreciated.
Rob
I think I've resolved my issue. The key was to divide "intNumberofWeeks" by
2. The following code seems to work fine...so far:
for(int i = 0; i <= intNumberofWeeks / 2; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDateTime, " +
"EventEndDateTime) VALUES " +
"('" + dtEventStartDateTime.AddDays(i * 14) + "', " +
"'" + dtEventEndDateTime.AddDays(i * 14) + "') ";
objConnection = new SqlConnection(dbPath);
objCommand = new SqlCommand(strInsert,objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close();
}
"Rob Johnson" <rj**********@comcast.net> wrote in message
news:M-********************@comcast.com... It's a bit more complex than that Ab. In order to determine how many
dates there are representing "Every other Week" starting on October 3, 2005 and ending on October 31, 2005, you first have to figure out how many entries there should be. In this case, there should be 3. A "for loop" is
required to loop through Oct 3 to Oct 31 and return either the number of days or weeks. Example, the code below will insert the correct number of entries
for an event that repeated every day from Oct 3 to Oct 31 (intNumberofDays is determined using TimeSpan):
if (EventFrequency == "Day") { for(int i = 0; i <= intNumberofDays; i++) { string strInsert = "INSERT INTO Events " + "(EventStartDateTime, " + "EventEndDateTime) VALUES " + "('" + dtEventStartDateTime.AddDays(i) + "', " + "'" + dtEventEndDateTime.AddDays(i) + "') ";
objConnection = new SqlConnection(dbPath); objCommand = new SqlCommand(strInsert,objConnection); objConnection.Open(); objCommand.ExecuteNonQuery(); objConnection.Close(); } }
The problem I'm running into is substituting "intNumberofDays" with "intNumberofWeeks" will return 5 weeks, where I really need it to return 3 weeks. "i" will then be 3 which I can plug into a revised SQL insert statement and use "dtEventStartDateTime.AddWeeks(i)" to populate my
database with the 3 dates representing "Every Other Week" (Oct 3, Oct, 17, Oct 31). Simply subtracting 2 weeks won't work since the duration of events entered by users can change from entry to entry.
"Abubakar" <ab*******@gmail.com> wrote in message news:Ot**************@TK2MSFTNGP12.phx.gbl... I think its as simple as adding number of days to the datetime type as:
DateTime dt = new DateTime(2005, 10, 3); dt=dt.AddDays(14);
now dt has 17th oct. You keep on adding days like that until the the end date comes, like in a loop.
Hope that helps.
Ab. http://joehacker.blogspot.com
"Rob Johnson" <rj**********@comcast.net> wrote in message news:nN********************@comcast.com... I have an ASP.Net calendar feature which allows users to add events
and configure whether or not they repeat at various frequencies (i.e,
daily, weekly, monthly, Sat/Sun, etc.). What I'm looking for is some C# code that will calculate a date of "Every Other Week" based on a starting date
and ending date.
Example: If a user enters an event dated October 3, 2005 and would
like it to repeat every other week until October 31, 2005, the code will
return the following dates:
October 3, 2005 October 17, 2005 October 31, 2005
Any help would be greatly appreciated.
Rob
There's no need to care about the number of inserts you're doing at the time
you're calculating it (unless of course you have this constraint).
DateTime dt = startDate;
int frequency = 14;
int insertCount = 0;
int maxInserts = 100; //may not be necessary for you...
//begin tran
while( dt <= endDate && insertCount < maxInserts )
{
//insert dt into your date table
dt.AddDays( frequency );
insertCount++;
}
if( insertCount >= maxInserts )
{rollback tran}
else
{commit tran}
"Rob Johnson" <rj**********@comcast.net> wrote in message
news:_Z********************@comcast.com... I think I've resolved my issue. The key was to divide "intNumberofWeeks" by 2. The following code seems to work fine...so far:
for(int i = 0; i <= intNumberofWeeks / 2; i++) { string strInsert = "INSERT INTO Events " + "(EventStartDateTime, " + "EventEndDateTime) VALUES " + "('" + dtEventStartDateTime.AddDays(i * 14) + "', " + "'" + dtEventEndDateTime.AddDays(i * 14) + "') ";
objConnection = new SqlConnection(dbPath); objCommand = new SqlCommand(strInsert,objConnection); objConnection.Open(); objCommand.ExecuteNonQuery(); objConnection.Close(); } "Rob Johnson" <rj**********@comcast.net> wrote in message news:M-********************@comcast.com... It's a bit more complex than that Ab. In order to determine how many dates there are representing "Every other Week" starting on October 3, 2005 and ending on October 31, 2005, you first have to figure out how many entries there should be. In this case, there should be 3. A "for loop" is required to loop through Oct 3 to Oct 31 and return either the number of days or weeks. Example, the code below will insert the correct number of entries for an event that repeated every day from Oct 3 to Oct 31 (intNumberofDays is determined using TimeSpan):
if (EventFrequency == "Day") { for(int i = 0; i <= intNumberofDays; i++) { string strInsert = "INSERT INTO Events " + "(EventStartDateTime, " + "EventEndDateTime) VALUES " + "('" + dtEventStartDateTime.AddDays(i) + "', " + "'" + dtEventEndDateTime.AddDays(i) + "') ";
objConnection = new SqlConnection(dbPath); objCommand = new SqlCommand(strInsert,objConnection); objConnection.Open(); objCommand.ExecuteNonQuery(); objConnection.Close(); } }
The problem I'm running into is substituting "intNumberofDays" with "intNumberofWeeks" will return 5 weeks, where I really need it to return 3 weeks. "i" will then be 3 which I can plug into a revised SQL insert statement and use "dtEventStartDateTime.AddWeeks(i)" to populate my database with the 3 dates representing "Every Other Week" (Oct 3, Oct, 17, Oct 31). Simply subtracting 2 weeks won't work since the duration of events entered by users can change from entry to entry.
"Abubakar" <ab*******@gmail.com> wrote in message news:Ot**************@TK2MSFTNGP12.phx.gbl... > I think its as simple as adding number of days to the datetime type > as: > > DateTime dt = new DateTime(2005, 10, 3); > dt=dt.AddDays(14); > > now dt has 17th oct. You keep on adding days like that until the the > end > date comes, like in a loop. > > Hope that helps. > > Ab. > http://joehacker.blogspot.com > > > "Rob Johnson" <rj**********@comcast.net> wrote in message > news:nN********************@comcast.com... > > I have an ASP.Net calendar feature which allows users to add events and > > configure whether or not they repeat at various frequencies (i.e, daily, > > weekly, monthly, Sat/Sun, etc.). What I'm looking for is some C# > > code > that > > will calculate a date of "Every Other Week" based on a starting date and > > ending date. > > > > Example: If a user enters an event dated October 3, 2005 and would like it > > to repeat every other week until October 31, 2005, the code will return > the > > following dates: > > > > October 3, 2005 > > October 17, 2005 > > October 31, 2005 > > > > Any help would be greatly appreciated. > > > > Rob > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wm |
last post by:
I have a client who needs a good web-based calendar for their website. What
they would like is something that can display a monthly calendar online,...
|
by: Pete..... |
last post by:
Hi all.
I'm trying to make a calendar for my webpage, python and html is the only
programming languages that I know, is it possible to make such...
|
by: Steve |
last post by:
Can someone recommend a way to display a one-month calendar view where the month
can be selected and up to six events can be shown in any day of the...
|
by: Shyguy |
last post by:
Is it possible to create a calendar that shows previous input data and
also allows for input of new data?
|
by: jodyblau |
last post by:
I am trying use a Calendar Control 10.0 in one of my forms. (I am
using access 2002)
What I want to do is have the user click a button which...
|
by: Kajsa Anka |
last post by:
Before I re-invent something I would like to ask if there exists some code
that can be used for create the HTML code for a calendar which I then can...
|
by: hal |
last post by:
Hello All,
I got this code somewhere, so i'm not even sure if this is the best
way to do this. Basically what i want is to display events in an...
|
by: swethak |
last post by:
Hi,
I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add...
|
by: swethak |
last post by:
hi,
i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily...
|
by: tammygombez |
last post by:
Hey fellow JavaFX developers,
I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: CD Tom |
last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |