Sample Header Ad - 728x90

Sum date between two date and group by month

0 votes
3 answers
13373 views
I have a table as below:
Name  Start Date  End Date
Joe   20/04/2021  20/05/2021
John  01/05/2021  28/05/2021
I am using a SQL table-valued function to return a table that has 2 columns: Month and Count total Date of this month. Example: - Joe: 10 days in Apr, 20 days in May - John: 28 days in May Finally I will return a new table Month|Count -|- 4|10 5|48 I tried to use datediff and datepart to group by month, but don't know how to sum after group. Is there any way to do this? Besides, I want to add filter from date and to date.
Asked by hem6d (15 rep)
May 25, 2021, 04:36 AM
Last activity: May 27, 2021, 02:07 PM