I’m calculating income of hiring equipments for a report. In that, hiring cost in weekend days will be plus 10% more if compare with normal days. So how can I calculate there’s how many weekend days between two dates. And in report query, I can’t use DECLARE also. Can someone help me to do this. Thank you so much
Advertisement
Answer
This should work:
DECLARE @StartDate DATETIME DECLARE @EndDate DATETIME SET @StartDate = '2012/11/01' SET @EndDate = '2012/11/05' SELECT (DATEDIFF(wk, @StartDate, @EndDate) * 2) +(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END) +(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)