The Start Time and end time of the working day are known.

Source: Internet
Author: User

It is known that the start time and work date are used to calculate the end time of a business day:

C #:

Public datetime getdate (datetime dtbegin, int workdays)
{

Datetime endtime;
Int J = 0;
Int I = 0;
Do
{
Endtime = dtbegin. Date. adddays (I );
I = I + 1;
If (endtime. dayofweek! = System. dayofweek. Saturday) & (endtime. dayofweek! = System. dayofweek. Sunday ))
{
J = J + 1;
}
}
While (J! = Workdays );
Return endtime;
}

 

SQL:
Create Function f_workdayadd (
@ Date datetime, -- base date
@ Workday int -- the number of working days to be added
) Returns datetime
As
Begin
Declare @ BZ int
-- Increase the number of days in a week
Select @ Bz = case when @ workday <0 then-1 else 1 end
, @ Date = dateadd (Week, @ workday/5, @ date)
, @ Workday = @ workday % 5
-- Increase the number of working days not for the whole week
While @ workday <> 0
Select @ date = dateadd (day, @ BZ, @ date ),
@ Workday = case when (@ datefirst + datepart (weekday, @ date)-1) % 7 between 1 and 5
Then @ workday-@ BZ else @ workday end
-- Avoid the processing date staying in the non-work period
While (@ datefirst + datepart (weekday, @ date)-1) % 7 in (0, 6)
Set @ date = dateadd (day, @ BZ, @ date)
Return (@ date)
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.