How to calculate the number of working days between two dates in MSSQL
MSSQL how to calculate the difference between the two dates of the number of working days, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
The code is as follows: if exists (select * from dbo.sysobjects where id = object_id (N' [dbo]. [f_WorkDay]') and xtype in (NFN, NFN, NFF')) drop function [dbo]. [f_WorkDay] GO-- calculate the number of working days that differ between the two dates CREATE FUNCTION f_WorkDay (@ dt_begin datetime) -- calculation start date @ dt_end datetime-calculation end date) RETURNS int AS BEGIN declare @ i int select @ i=abs (datediff (dd,@dt_begin,@dt_end)) declare @ t table (dt datetime) if @ dt_begin > @ dt_end insert @ t select dateadd (dd,number,@dt_end) from master..spt_values where number