troubleshooting Question

working with date and manipulation of dates added to database

Avatar of lobos
lobos asked on
8 Comments1 Solution224 ViewsLast Modified:
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 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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros