Date addition for excluding holidays

Source: Internet
Author: User
  • Function running environment: Holiday data is stored in the database table in the following format:

// Determine whether the date is a holiday
Private bool isholiday (datetime DT)
{
Database DB = databasefactory. createdatabase ("sqldbconnection ");
String SQL = @ "select count (*)
From [oa_sys_holiday]
Where [date] = @ starttime ";
Bool result = false;
Using (dbcommand comm = dB. getsqlstringcommand (SQL ))
{
DB. addinparameter (Comm, "@ starttime", dbtype. String, DT. tow.datestring ());
If (INT) dB. executescalar (Comm)> 0)
{
Result = true;
}
}

Return result;
}

 

// Date addition (excluding holidays)
Private datetime adddaywithoutholiday (datetime startdate, int days)
{
While (isholiday (startdate) // skip holidays (ensure that the start time is not a holiday): If the start time is a holiday, locate the end time of the holiday as the start time
{
Startdate = startdate. adddays (1 );
Datetime dt = startdate. date;
Startdate = DT;
}
For (INT I = 0; I <days; I ++)
{
Startdate = startdate. adddays (1 );
If (isholiday (startdate ))
{
Do
{
Startdate = startdate. adddays (1 );
} While (isholiday (startdate ));
}
}
Return startdate;
}

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.