TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kwasi Denkyira
1.5k
194
14.6k
Get Weekly Business dates for a given two dates range
Feb 21 2019 8:32 PM
I want to generate weekly business dates between two dates excluding weekends and holidays. So I want a results
week 1
StartDate {2/18/2019 12:00:00 AM}
EndDate{2/25/2019 12:00:00 AM---wrong end date} ---> 2/27/2019 correct end date
week 2
StartDate {2/25/2019 12:00:00 AM}
EndDate{3/4/2019 12:00:00 AM--wrong end date}----->3/6/2019 -- correct end date
Below is my code. Any help will be appreciated
class
Program
{
public
class
WeekStartEnd
{
public
DateTime firstDate;
public
DateTime SecondDate;
}
static
void
Main(
string
[] args)
{
//usage:
DateTime StartDate = DateTime.Parse(
"02/12/2019"
);
DateTime SeriesEndDate = DateTime.Parse(
"12/31/2025"
);
DateTime firstMonday = Enumerable.Range(1, (SeriesEndDate - StartDate).Days +1)
.SkipWhile(x => StartDate.AddDays(x).DayOfWeek != DayOfWeek.Monday)
.Select(x => StartDate.AddDays(x))
.First();
TimeSpan ts = (TimeSpan)(SeriesEndDate - firstMonday);
List<WeekStartEnd> dates =
new
List<WeekStartEnd>();
for
(
int
i = 0; i < ts.Days; i += 7)
{
dates.Add(
new
WeekStartEnd() { firstDate = firstMonday.AddDays(i), SecondDate = firstMonday.AddDays(i + 7) });
}
Console.WriteLine(dates);
}
}
}
Reply
Answers (
4
)
mvc web forms data flow to database
pdf is not showing correct hindi.