Run through loop for week and don't select weekends

dvar

New Member
So the user can select 2 different dates, a start date and an end date from 2 calendars, when they click \[code\]add\[/code\] the dates between&including the dates selected will be added to the Database, each date as a separate record.This works fine however I don't want weekends to be added to the Database.I've updated the UI of datepicker http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerCustomCellRender.htmlbut if a user selects fri-mon for example \[code\]fri,sat,sun and mon\[/code\] will be added to the Database.I've tried to only run the code if datyofweek is not saturday or sunday\[code\] public ActionResult listHolidays(Holiday holiday, int? PersonId, string HolidayDate, string endDate) { DateTime startDates = Convert.ToDateTime(HolidayDate), endDates = Convert.ToDateTime(endDate); while (startDates <= endDates) { if (startDates.DayOfWeek != DayOfWeek.Saturday || startDates.DayOfWeek != DayOfWeek.Sunday) { Holiday holiday1 = new Holiday(); holiday1.PersonId = PersonId.Value; holiday1.HolidayDate = startDates; db.Holidays.AddObject(holiday1); db.SaveChanges(); startDates = startDates.AddDays(1); } } return RedirectToAction("Index"); }\[/code\]any help?Thanks
 
Back
Top