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
MySQL WEEKDAY() Function The WEEKDAY() function returns the weekday number for a given date. Note: 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.
Here's one way: SELECT early_date , late_date , ( TRUNC (late_date + 1, 'IW') - TRUNC (early_date, 'IW') ) / 7 AS sundays FROM table_x ; This does not depend on your NLS settings.
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)
http://sqlfiddle.com/#!3/d41d8/5707/0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With