Get the App
SLTechnology News&Howtos  ›  Database  › 

How to calculate the number of working days between two dates in MSSQL

Shulou Source: shulou.com Published: 2022-05-31 19:25:35 10月03日 Update

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

Tags: Date two days work help clear code content for this article novice more knowledge industry information information channel problem demand channel enter one Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Information Docker MySQL vpn