473,666 Members | 2,144 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 6114
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
3708
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, like when you print a monthly calendar from M$ Outlook.) They want to be able to easily edit it...
2
4102
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 the time, and the user should be able
7
4503
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
3762
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 events that aren't available to me. Most notably, any click events.
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 calendar view (and/or a monthly) with my schedule.
6
2243
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 calendar control.
1
4895
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 displyed in same td row not the text box. and also i add the events to that calendar.plz advice how to...
1
3442
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type"...
0
8356
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.