working with date and manipulation of dates added to database
Posted on 2007-07-27
I am creating a C# web calendar of activities. And working on this repeating a day's event on a calendar type of idea, and for each day I insert a record to a database.
So I have a start date and end date and use the following logic to determine the amount of days(records) to
insert. (each record is a day).
DateTime sDate = DateTime.ParseExact(startDate, "M/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime eDate = DateTime.ParseExact(endDate, "M/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
int numTimesToRepeat = ((TimeSpan)(eDate - sDate)).Days;
numTimesToRepeat = numTimesToRepeat + 1;
numTimesToRepeat is the amount of times I insert a record to the database and increment the date by one...
The question I have is how do I do this if I only want to insert a record for say every other day..so it would starting with the start date day, and then every other day until the end day. (only to include week days). ie. Mon, Wed, Fri
Also I want to insert a record for every first monday of the month. So it would starting with the start date day, and then every first Monday of the month until the end date.
I'm not completely familiar with the date feature and how to accomplish what I need, but I am pretty sure this can be done.
Any assistance would be greatly apprecited.
I will increase the points if required