Trying to find how much an item has been in use over a month, so I've got this bit of sql (MySql):
SUM(IF(bk_status='2' OR bk_status='3' OR bk_status='4' , DateDiff( end_d + INTERVAL 1 DAY,start_d ),0)) AS rentdays
this is fine up to a point:
if the item was booked 3-5 Jan and 30-31 Jan I get the result 5
BUT if the item ran over into February, so the last booking is 30 Jan -2 Feb I will get 7
whereas within January it is 5 days of usage
So I need to clip the end date to the number of days in the month
I could get all the items and put them through PHP array manipulations but anyone know how to clip it in sql ?