473,581 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calendar - Repeating Events

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
Nov 17 '05 #1
4 6111
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(1 4);

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**********@c omcast.net> wrote in message
news:nN******** ************@co mcast.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

Nov 17 '05 #2
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 (intNumberofDay s is
determined using TimeSpan):

if (EventFrequency == "Day")
{
for(int i = 0; i <= intNumberofDays ; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDat eTime, " +
"EventEndDateTi me) VALUES " +
"('" + dtEventStartDat eTime.AddDays(i ) + "', " +
"'" + dtEventEndDateT ime.AddDays(i) + "') ";

objConnection = new SqlConnection(d bPath);
objCommand = new SqlCommand(strI nsert,objConnec tion);
objConnection.O pen();
objCommand.Exec uteNonQuery();
objConnection.C lose();
}
}

The problem I'm running into is substituting "intNumberofDay s" with
"intNumberofWee ks" 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 "dtEventStartDa teTime.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*******@gmai l.com> wrote in message
news:Ot******** ******@TK2MSFTN GP12.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(1 4);

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**********@c omcast.net> wrote in message
news:nN******** ************@co mcast.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


Nov 17 '05 #3
I think I've resolved my issue. The key was to divide "intNumberofWee ks" by
2. The following code seems to work fine...so far:

for(int i = 0; i <= intNumberofWeek s / 2; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDat eTime, " +
"EventEndDateTi me) VALUES " +
"('" + dtEventStartDat eTime.AddDays(i * 14) + "', " +
"'" + dtEventEndDateT ime.AddDays(i * 14) + "') ";

objConnection = new SqlConnection(d bPath);
objCommand = new SqlCommand(strI nsert,objConnec tion);
objConnection.O pen();
objCommand.Exec uteNonQuery();
objConnection.C lose();
}

"Rob Johnson" <rj**********@c omcast.net> wrote in message
news:M-*************** *****@comcast.c om...
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 (intNumberofDay s is
determined using TimeSpan):

if (EventFrequency == "Day")
{
for(int i = 0; i <= intNumberofDays ; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDat eTime, " +
"EventEndDateTi me) VALUES " +
"('" + dtEventStartDat eTime.AddDays(i ) + "', " +
"'" + dtEventEndDateT ime.AddDays(i) + "') ";

objConnection = new SqlConnection(d bPath);
objCommand = new SqlCommand(strI nsert,objConnec tion);
objConnection.O pen();
objCommand.Exec uteNonQuery();
objConnection.C lose();
}
}

The problem I'm running into is substituting "intNumberofDay s" with
"intNumberofWee ks" 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 "dtEventStartDa teTime.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*******@gmai l.com> wrote in message
news:Ot******** ******@TK2MSFTN GP12.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(1 4);

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**********@c omcast.net> wrote in message
news:nN******** ************@co mcast.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



Nov 17 '05 #4
Sal
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**********@c omcast.net> wrote in message
news:_Z******** ************@co mcast.com...
I think I've resolved my issue. The key was to divide "intNumberofWee ks"
by
2. The following code seems to work fine...so far:

for(int i = 0; i <= intNumberofWeek s / 2; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDat eTime, " +
"EventEndDateTi me) VALUES " +
"('" + dtEventStartDat eTime.AddDays(i * 14) + "', " +
"'" + dtEventEndDateT ime.AddDays(i * 14) + "') ";

objConnection = new SqlConnection(d bPath);
objCommand = new SqlCommand(strI nsert,objConnec tion);
objConnection.O pen();
objCommand.Exec uteNonQuery();
objConnection.C lose();
}

"Rob Johnson" <rj**********@c omcast.net> wrote in message
news:M-*************** *****@comcast.c om...
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 (intNumberofDay s is
determined using TimeSpan):

if (EventFrequency == "Day")
{
for(int i = 0; i <= intNumberofDays ; i++)
{
string strInsert = "INSERT INTO Events " +
"(EventStartDat eTime, " +
"EventEndDateTi me) VALUES " +
"('" + dtEventStartDat eTime.AddDays(i ) + "', " +
"'" + dtEventEndDateT ime.AddDays(i) + "') ";

objConnection = new SqlConnection(d bPath);
objCommand = new SqlCommand(strI nsert,objConnec tion);
objConnection.O pen();
objCommand.Exec uteNonQuery();
objConnection.C lose();
}
}

The problem I'm running into is substituting "intNumberofDay s" with
"intNumberofWee ks" 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 "dtEventStartDa teTime.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*******@gmai l.com> wrote in message
news:Ot******** ******@TK2MSFTN GP12.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(1 4);
>
> 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**********@c omcast.net> wrote in message
> news:nN******** ************@co mcast.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
> >
> >
>
>



Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3707
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, with a display that's large enough that you can see the events listed in each day's box. (i.e., not just a numerical calendar but one where the event time and title appear in the monthly view,...
2
4093
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 a calendar with pythong code and some html. The Idea is that when I click the link calendar on my webpage, then the user will be linked to the calendar. The calendar should show one month at...
7
4499
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 calendar. The events and dates would be stored in an events table and any event may be for one day or multiple days. Thanks! Steve
8
2451
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?
2
3761
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 makes the calendar visible. Then when the user clicks on a date, it sends it to a text box and then the calendar should disappear. All of the examples I have been able to track down seem to use...
2
4914
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 include on a web page. The module in the standard library can create a calendar but I would like display my schedule. My idea is that it would read a simple text file and then create a weekly...
6
2242
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 asp.net calendar control which i'm able to do, but not when i have two events on the same day. I'm getting the data for the events from an XML file. Here's my code. aspx page just has the...
1
4892
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 the events to calendar. In that code displys the events when click on that date that perticular event displyed in a text box.But my requirement is to when click on that date that related event...
1
3439
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 calendar.Any body plz suggest that what modifications i have to made in my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
0
7876
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7804
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.