Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report