I will be having a dynamic date range(from & To date), I need to find all the month names & number of days in between that date range, the from & To date may or may not be a full month, so the no. of days should be calculated accordingly.
Sample, Input & Output below
I tired looking through all similar topics but couldn’t find an exact one, apologies if it is a duplicate one.
I am trying to build a solution using while loop unsuccessfully, wondering if there is any LINQ for such scenarios.
@Yoichi Thanks a lot, this works, though I had to spend some time to understand the steps especially the operations being performed in Invoke method, if you could please add one line descriptions as well, for instance, how is the method calculating the number of days of the partial month?, it might be helpful for others also:-).
Secondly, my input dates will be in format MM/dd/YYYY, if I tried this format for partial end date, the output was wrong, instead of giving partial number of days it was giving total number of days for the month.
if you could please add one line descriptions as well, for instance, how is the method calculating the number of days of the partial month?, it might be helpful for others also:-).
Thank you for your advice. The above logic is as follows:
From the start date to the end date, adding day one by one. Then value of dictionary the month of the day as key is added 1 to dictionary.
We can convert the string to DateTime type using DateTime.ParseExact method as the following.