Subject: find days per month in a date range
Posted By: rojer Post Date: 5/3/2007 11:24:14 PM
How to  find days per month in a date range  ?

For eg i have a start date - 04/28/2007 (mm/dd/Y) and end date 05/04/2007 , i have to find the days in each month that comes in the above date range

in the above eg the days in April are 3 and in May the days are 5

Reply By: jmaronilla Reply Date: 6/5/2007 7:36:27 PM
rojer,

try this:
SELECT DATEDIFF(start_date, LAST_DAY(start_date)) + 1 AS rdosd,
DAYOFMONTH(end_date) AS doed
FROM TableOfDates;

rdosd: Remaining Days of start_date
doed: Days of end_date

Hope it works,
john





Go to topic 59634

Return to index page 1