Hi all,
i have created a table macro to calculate number of days between two dates (start date to end date). below i have mentioned the query . could you help me to modify to exclude weekends?
select *,(CAST(ROUND(ceiling(DATEDIFF(DAY,'Start Date','END Date')))as int))+1+ " days" as 'Duration' from T1
Thanks
You could take the number of days, divide by 7 to get weeks, then multiply by 2 to get the weekends, and then subtract that value from the number of days. Should get you fairly close.
Some SQL examples can be found here: https://stackoverflow.com/questions/7388420/get-datediff-excluding-weekends-using-sql-server
hi Doyle ,
i have updated my query, what are the filed to be modified to complete this table in settings?
SELECT *, 'Days' - 2 * (('Days' / 7)::integer) - CASE WHEN 'Days' % 7 = 0 THEN 0 WHEN 'Start date'::Date->getDay() = 0 THEN 1 WHEN 'Start date'::Date->getDay() + 'Days' % 7 = 7 THEN 1 WHEN 'Start date'::Date->getDay() + 'Days' % 7 > 7 THEN 2 ELSE 0 END AS 'Work days' FROM (SELECT *, ROUND((T1.'End date' - T1.'Start date') / "1d") + 1 AS 'Days' FROM T1)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.