Get Next business day conditionally

Hi All,
I have a calendar table with all federal holidays, saturdays and sundays flagged to 1.
I need help in finding the next business day from givendate and that too Conditionallly.. means
Lets say today's date is 01/02/2014(wednesday) and I want to know the next businessday after 10 days which would be 01/16/2014(thursday). Exclude saturdays and sundays in between.
I started like this..but gives me wrong date..
Also, when 10th day is saturday or sunday or any holiday it should give next business day.
so i need help in tweaking my query.
select NextBusinessDay = min(a.Date)+10
from  [dbo].[Calendar] a
where
 a.Date > GETDATE() 
 and a.day_Name not in ('Saturday','Sunday')
 and a.IsHoliday <> 1
Thanks,
RH
sql

Try this out:
DECLARE @calendar TABLE (date DATE, holiday BIT, weekend BIT)
DECLARE @i INT = 0
SET NOCOUNT ON
WHILE @i < 50
BEGIN
INSERT INTO @calendar (date, holiday, weekend)
VALUES (DATEADD(DAY,@i,'2014-01-01'),0,CASE WHEN DATEPART(WEEKDAY,DATEADD(DAY,@i,'2014-01-01')) IN (1,7) THEN 1 ELSE 0 END)
SET @i = @i + 1
END
UPDATE @calendar SET holiday = 1 WHERE date = '2014-01-20'
SET NOCOUNT OFF
SELECT max(date)
FROM (
SELECT TOP 10 *
FROM @calendar
WHERE date > '2014-01-02'
AND holiday <> 1
AND weekend <> 1
) a
Obviously I've simulated your calendar, and forced a date into it.

Similar Messages

  • 5. We need additional time to process your transaction You should get an email from us by next business day. If you don't hear back from us, you can check your order status on your account page or call us at +1 800-585-0774. If you're not in North America

    Step 5.
    5. We need additional time to process your transaction You should get an email from us by next business day. If you don't hear back from us, you can check your order status on your account page or call us at +1 800-585-0774. If you're not in North America, you can look up a local number here. For now, check out all the great free features of Creative Cloud! Get started with trials
    I keep getting this.
    The Bank and Paypal states that Adobe needs to process my transaction twice.
    I have no order number/ no status nor contact from Adobe. I called customer service and he transferred me to sales where the phone rang with no answer.

    Since this is an open forum, not Adobe support... you need to contact Adobe staff to help
    Adobe contact information - http://helpx.adobe.com/contact.html
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • "Onsite Next Business Day Warranty" - Current Warranty Request/Warranty Issues/Poor Service

    TL;DR at the bottom of the post, detailed information in between.   I have had a T430s for a little less than three years.  I have called the warranty/customer service ~5+ times and every time gotten extremely poor service, whether it be because parts were "backordered" for weeks at a time, or because "Next Business Day" service has been anything but. I have decided to take a different route for my most recent warranty request, I will keep an up to date account of my request via this forum, with the intent of informing as many as possible with the current state of "Onsite Next Business Day Warranty". I called the warranty ~1hr ago and filed a service request.  The outcome of the request was that "I should receive a call in the next day or so, no later than 5:30PM tomorrow" when the employee I spoke with arrives in the office.  I pressed as to who would call, the employee would not answer definitively, but hinted that it would be his manager, because my warranty request apparently contained "so many parts that it required approval".  The parts have not been shipped, and it was abundantly clear that the subject of the call would be whether this warranty request would get approved. Hopefully, readers can already tell where this is going, next business day onsite repair apparently means in the next 24 hours, you will receive a phone call letting you know if Lenovo will honor their warranty obligations that have already been paid for. To detail my issues:1. The fingerprint scanner has stopped working for the second time. 2. I have had an issue where when I pick up the laptop on the lefthand side, the screen turns to 'snow' and will not return to its regular condition until next boot.  The laptop is unusable in this condition.  I have been attempting to get this fixed essentially since I purchased the laptop, however, after 3 technicians came to 'fix' the issue, it has not been solved.  I have asked/suggested every time I have called the warranty line that the issue is the system board, and it needs to be replaced.  Every time, they have refused to replace the system board, instead opting for other parts, some of which were on 'backorder' for over a month (remember, "Next Business Day Onsite Repair").  The difficulty in obtaining warranty service from Lenovo has caused me to only attempt to get this fixed when other issues pop up, as they have in this case.  Frankly, this issue alone should have caused Lenovo to call this laptop what it is after warranty request #2, a lemon, and they should have/should send a replacement model. 3. The laptop will not 'awake' from sleep mode - when the lid is closed, the keyboard/power button will not respond, and all power sources (battery, charger cable) must be removed and the laptop restarted. 4.  When the laptop is booted up, there is a 'CMOS' error message - I have never had a BIOS battery 'go' in this short a time frame. Issues 1,3, and 4 have cropped up in the last week. The warranty employee suggested that I might need to send my laptop in for 'Depot' repair instead of onsite, which in this instance will not work because of the significant delay that may entail.  I have a professional licensing/certification exam this month, and would greatly prefer that my laptop be in tip-top shape for the exam.  The need to have the greatest level of uptime is what caused me to pay for the NBD Onsite Warranty in the first place. My previous (horrible) warranty experiences and requirement for expedient repair have led me to seek a better method for resolving issues, namely airing them in a public forum, which hopefully will elicit a response from someone who can actually get things done in the warranty department. I have 0 hope of receiving next business day repair (or even repair by Friday, as the warranty explictly says calls received after 4:00 PM might take 2 business days).  I am skeptical that the issue will be resolved in the next week or two. Likewise, I have little hope that [some of] the problem(s) will actually get resolved after "repair" has been made, as historically that has not been the case for me with this laptop.  I will be voting with my dollars after this, as I have been uniformly unimpressed with Lenovo customer service/warranty/etc.  The laptop has been very nice when it doesn't have issues (and when I don't forget to grab it in a certain way), however, everything else about Lenovo has been exceedingly frustrating. The TL;DR of this is:1. If you work for Lenovo and can help, or if you don't and can help, please do!!!  I will be extremely grateful for any assistance. 2. DO NOT under any circumstances purchase the Onsite NBD warranty thinking that the warranty will live up to the title.  I have never received NBD Onsite warranty service, despite repeatedly 'giving' the option to Lenovo to provide such service. 3. If you are considering purchasing a Lenovo product, please read some of the stories people have on their dealings with the support side of the business.  I will speak for myself and say that I will almost certainly never buy another Lenovo product again, and will strongly encourage everyone I know to do the same - after recounting my issues with them.  

    Hey burgerbone,
    Sorry to hear about your troubles getting your machine issues resolved. I am not sure of the onsite policy related to your symptoms but I will be happy to look into it for you.
    Do you mind sending me a PM (Private Message) with your machine/case info?
    Thanks!
    Ty

  • 3 Years Next Business Day On-Site Warranty Registration

    Hello,
    I bought a warranty extension for my laptop, it is a warranty for 3 Years Next Business Day On-Site service. Now i tried to register the service and it reqognized de certificate number I gave. But when i finished with putting in my serial key, adress and all that, I was said that the registration couldn't be fully completed without a copy of the receipt i got when i bught the warranty.
    Now that wouldn't be so hard right, except for the fact that there was no e-mail adress given for me to send a copy of my receipt to. So could i get the e-mail adress where i'm supposed to send it to, please?

    If you check this section you can find many threads with e-mail address where you can contact Toshiba.
    By the way contact details can be found at http://eu.computers.toshiba-europe.com/innovation/contact_toshiba.jsp

  • Not giving paid for next business day service

    Hi Has anybody got a number I can phone in the uk for customer complaints? My nine month old thinkpad screen went. Company paid for extra next business day service for repairs. At first they said they didn't have a replacement and it would take an unknown amount of time to find one. When I asked to speak to a supervisor they found one.Next business day then became two days later because they sent out requests to all engineers by 3pm. I had the contract in front of me saying they had to receive the call by 4pm. They said sorry there is nothing they could do about it. Why bother paying for next day - poor service for a premium price.

    Hello MacLux,
    I was disappointed to read that your order wasn't processing in line with the communications you'd received. I apologize for any inconvenience to you.
    Using the information you provided when you signed up for Best Buy Unboxed, I was able to locate your order. I note that your order was cancelled shortly after you posted your message. It also seems that a new order was placed early this morning. For the new order, the shipment is currently awaiting pickup from our warehouse by the carrier.
    If you have questions or concerns, please let me know. I'm very grateful that you wrote to us.
    Sincerely,
    John|Social Media Specialist | Best Buy® Corporate
     Private Message

  • Printer Care Pack Next Business Day

    I purchased the "Printer Care Pack Next Business Day" for the LaserJet 500dn about 1 month ago and when I attempt to register it online it will not allow me to pass the stage of entering the serial and product number.
    Any help would be appreciated.
    Thanks
    Michael

    Hi @MM_Vienna ,
    I have brought your issue to the attention of an appropriate team within HP. They will likely request information from you in order to look up your case details or product serial number. Please look for a private message from an identified HP contact. Additionally, keep in mind not to publically post ( serial numbers and case details).
    If you are unfamiliar with how the Forum's private message capability works, you can learn about that here.
    Regards,
    George
    I work for HP

  • Recursive CTE to get first business day excluding public holidays

    I wanted to write a recursive CTE to calculate the first business day excluding the public holidays for a given year. I have a table with the public holiday for that same year

    I like the functions I built to get this done:
    create function NthDayOfMonth (@year int, @month smallint, @weekday varchar(15), @nth smallint)
    returns datetime
    as
    begin
    declare @the_date datetime, @c_date datetime, @cth smallint
    set @cth = 0
    set @c_date = convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'
    while month(@c_date) = @month
    begin
    if datename(weekday,@c_date) = @weekday set @cth = @cth + 1
    if @cth = @nth and datename(weekday,@c_date) = @weekday set @the_date = @c_date
    set @c_date = dateadd(day,1,@c_date)
    end
    return @the_date
    end
    GO
    create function Holidays(@year int)
    returns @table table
    date date,
    type varchar(10),
    name varchar(25)
    as
    begin
    insert into @table
    select convert(datetime,convert(varchar,@year)+'-01-01') as date,'Holiday' as type ,'New Years Day' as name UNION ALL
    select dbo.NthDayOfMonth(@year,2, 'Monday',3),'Holiday','Family Day' UNION ALL
    select dateadd(d,0-case when datepart(weekday,convert(varchar,@year)+'-05-25') in (1,2) then 5+datepart(weekday,convert(varchar,@year)+'-05-25') else datepart(weekday,convert(varchar,@year)+'-05-25')-1 end, convert(varchar,@year)+'-05-25') ,'Holiday','Victoria Day' UNION ALL
    select convert(varchar,@year)+'-07-01' ,'Holiday','Canada Day' UNION ALL
    select dbo.NthDayOfMonth(@year,8, 'Monday',1),'Holiday','Civic Holiday' UNION ALL
    select dbo.NthDayOfMonth(@year,9, 'Monday',1),'Holiday','Labour Day' UNION ALL
    select dbo.NthDayofMonth(@year,10,'Monday',2),'Holiday','Thanksgiving' UNION ALL
    select convert(varchar,@year)+'-11-11' ,'Holiday','Rememberance Day'UNION ALL
    select convert(varchar,@year)+'-12-25' ,'Holiday','Christmas Day' UNION ALL
    select convert(varchar,@year)+'-12-26' ,'Holiday','Boxing Day' UNION ALL
    SELECT CONVERT(DATE,CONVERT(VARCHAR,@year) + '-0'+CONVERT(VARCHAR, FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25))+'-'+CONVERT(VARCHAR,CONVERT(INT,(((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + (FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25)) + 19) % 32,0))),'Holiday','Easter Sunday' UNION ALL
    SELECT DATEADD(DAY,-2,CONVERT(DATE,CONVERT(VARCHAR,@year) + '-0'+CONVERT(VARCHAR, FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25))+'-'+CONVERT(VARCHAR,CONVERT(INT,(((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + (FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25)) + 19) % 32,0)))),'Holiday','Good Friday' UNION ALL
    SELECT DATEADD(DAY,1,CONVERT(DATE,CONVERT(VARCHAR,@year) + '-0'+CONVERT(VARCHAR, FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25))+'-'+CONVERT(VARCHAR,CONVERT(INT,(((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + (FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25)) + 19) % 32,0)))),'Holiday','Easter Monday'
    update @table
    set date =
    case when MONTH(date) = 12 AND name != 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when MONTH(date) = 12 AND name != 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,1,date)
    when MONTH(date) = 12 AND name = 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when MONTH(date) = 12 AND name = 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,2,date)
    when MONTH(date) = 12 AND name = 'Boxing Day' and datepart(weekday,date) = 2 then dateadd(day,1,date)
    else date
    end
    return
    end
    GO
    create function Dates(@date datetime)
    returns @table table
    now datetime,
    today datetime,
    Month_start datetime,
    Month_end datetime,
    Prev_Month_Start datetime,
    Prev_Month_End datetime,
    Week_Start datetime,
    Week_End datetime,
    Prev_Week_Start datetime,
    Prev_Week_End datetime,
    Quarter_Start datetime,
    Quarter_End datetime,
    Prev_Quarter_Start datetime,
    Prev_Quarter_End datetime,
    Year_Start datetime,
    Year_End datetime,
    Prev_Year_Start datetime,
    Prev_Year_End datetime,
    Month_End_TS datetime,
    Prev_Month_End_TS datetime,
    Week_End_TS datetime,
    Prev_Week_End_TS datetime,
    Quarter_End_TS datetime,
    Prev_Quarter_End_TS datetime,
    Year_End_TS datetime,
    Prev_Year_End_TS datetime,
    Year smallint,
    Month smallint,
    Day smallint,
    Month_Name varchar(15),
    Day_Name varchar(15),
    WD SMALLINT,
    Week INT,
    isHoliday bit
    as
    begin
    if @date IS NULL set @date = getdate()
    insert into @table
    select
    @date as now,
    convert(datetime,convert(varchar,@date,101)) as today,
    dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
    dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
    dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
    dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
    dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
    dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
    dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
    dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
    convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
    convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
    dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
    dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
    dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
    dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
    dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
    dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
    dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
    dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
    dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
    dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
    Year(@date) as Year,
    Month(@date) as Month,
    Day(@Date) as Day,
    datename(month,@Date) as Month_Name,
    datename(WEEKDAY,@date) as Day_Name,
    datepart(weekday,@date) as WD,
    DATEPART(WEEK,@date) AS Week,
    COALESCE((SELECT 1
    FROM dbo.Holidays(YEAR(@date)) h
    WHERE h.date = @date),0) AS isHoliday
    return
    end
    go
    The holidays function is set up for Saskatchewan right now, but its a small matter to adjust it to your region.
    You can then do this:
    DECLARE @calendar TABLE (date DATE)
    WHILE (SELECT COUNT(*) FROM @calendar) < 365
    BEGIN
    INSERT INTO @calendar (date)
    VALUES (DATEADD(day,1,(SELECT COALESCE(MAX(date),CURRENT_TIMESTAMP) FROM @calendar)))
    END
    SELECT MONTH(date) AS month, MIN(date) AS fbd
    FROM @calendar c
    CROSS APPLY dbo.Dates(c.date)
    WHERE DATEPART(DAY,c.date) NOT IN (1,7) AND isHoliday = 0
    GROUP BY MONTH(date)

  • Calculate "Business Days" and account for holidays

    I have played with Date math based on what I have found for documentation, and adding an arbitrary number of days is pretty easy. But what about adding an arbitrary number of business days? I found a web site that talks about "Next business day",
    which could be adapted I am sure, but it only accounts for weekends. I want to calculate the date an arbitrary number of business days from a provided date. So, +3 business days calculated from a Monday should produce the date of the following Thursday,
    and calculated from a Friday should produce the date of the next Wednesday. And calculated from Friday Sept 4, 2015 (Friday before Labor Day) should produce Thursday Sept 10, 2015.
    Given that Windows is very business focused, I wonder if there is some nice hidden .NET functionality to calculate business days based on holidays as well? I know, some offices might give extra days off, four day weekends, etc. But those would be edge case
    enough to be safely ignorable for my purposes. Indeed, even holidays could probably be ignored, but if there is a quick approach I would rather use it. If I would need to code some sort of Exchange calendar scraper or some such, I'll live with just accounting
    for weekends. ;)

    You can pull holiday info from outlook.hol file and do the date math based on it. It won't be 100% reliable though. Not all the holidays listed in calendar are non-business days (not in all countries at least). International support may also present additional
    issues: in some countries it is a common practice to "move" weekend days to fill a single day gap between holidays and weekend (which screws up next business day calc anyway, regardless of holiday info :-). Not to mention all the possible industry-wide
    or company specific policies regarding working days.
    Gleb.

  • Need to return Business Days

    Post Author: latingntlman
    CA Forum: WebIntelligence Reporting
    I have two date fields:  EstDateofDeparture and  EstDateofArrival.
    My problem is when EstDateofDeparture falls on a Friday then EstDateofArrival shows on a Saturday and we don't deliver on Saturdays.We do have departures on Saturdays but no pickups on Sats and sundays.
    So I need the EstDateofArrival to be the following business day (Monday).Here's an example below:
    EstDateofDeparture:  Friday, Dec 7th, 2007EstDateofArrival:       Saturday, Dec 8th, 2007  (it needs to be Monday, Dec 10th, 2007 -- next business day).
    Example # 2:
    EstDateofDeparture:  Saturday, Dec 8th, 2007EstDateofArrival:       Sunday, Dec 9th, 2007  (it needs to be Monday, Dec 10th, 2007 -- next business day).
    T-SQL has a functionalilty where you could for example add getdate()-1 or getdate()+2.
    But I can't find anything in webi formula editor that shows me how to I can do that.
    Is there a function for this??
    thx,
    John

    Post Author: jsanzone
    CA Forum: WebIntelligence Reporting
    John,
    You will need to use a combination of two functions:
    =If(DayName(&#91;EstDateofDeparture&#93;)="Saturday";RelativeDate(&#91;EstDateofDeparture&#93;;2); if(DayName(&#91;EstDateofDeparture&#93;)="Sunday";RelativeDate(&#91;EstDateofDeparture&#93;;1);   &#91;EstDateofDeparture&#93;))
    Use the DayName() function to determine if it is a Saturday (and if so add two days, else add 1 day for a Sunday), and use the RelativeDate() function when adding days to a date.  If the day is neither Saturday or Sunday then leave the EstDateofDeparture in-tact.

  • Function, procedure to find next 10 business days

    Hi,
    Is there any function procedure to find next 10 business days in oracle.
    Also i have a local holiday table which are non-working days.
    Thanks.

    user7987260 wrote:
    Hi,
    Is there any function procedure to find next 10 business days in oracle.
    Also i have a local holiday table which are non-working days.
    Thanks.Welcome to OTN!
    This forum is for PL/SQL Developer questions. SQL and PL/SQL questions have their own forum that you can find under the Oracle Database heading. You should get a better answer if you ask your question there

  • Function, procedure to find next "x" business days

    Hi,
    Is there any function procedure to find next 10 business days in oracle.
    Also i have a local holiday table which are non-working days.
    Thanks.

    Hi,
    Ramin showed how to get the next 10 days.
    If you want to exclude holidays and weekends, and get only the 10th day, then you can do something like this:
    WITH     next_hundred_days     AS
         SELECT  TRUNC (SYSDATE) + LEVEL          AS bnsdate
         FROM      dual
         CONNECT BY     LEVEL <= 100
    ,     work_days          AS
         SELECT     n.bnsdate
         ,     ROW_NUMBER () OVER (ORDER BY bnsdate)     AS day_num
         FROM           next_hundred_days  n
         LEFT OUTER JOIN      holidays         h  ON  h.dt  = n.bnsdate
         WHERE   TO_CHAR ( bnsdate
                   , 'Dy'
                   , 'NLS_DATE_LANGUAGE=ENGLISH'
                   )     NOT IN ('SAT', 'SUN')
         AND     h.dt          IS NULL
    SELECT  bnsdate
    FROM     work_days
    WHERE     day_num     = 10
    ;This assumes that there will be at least 10 work days in the next 100 days. Where I work, that's a very safe assumption.
    I hope this answers your question.
    If not, post CREATE TABLE and INSERT statements for a few rows from your holiday table.
    Post a few (starting date, number of days) pairs, and the results that you would want from each pair, given the data you posted in the holiday table.
    See the forum FAQ {message:id=9360002}

  • Getting birthdays in the next 30 days

    Hello,
    i have a database which is filled with information about all the people you know. One of the columns in the database is the birthday of this person.
    Now i would like to know which persons gonna have their birthday in the next 30 days.
    If it is possible I would get these persons with 1 SQL-Query but I think it is not that obvious.
    Another way is to get all birthdays and process them with Java code which I know how to do this, but I think it will be more efficient with 1 SQL-Query.
    But the problem with the SQL-Query is that you must not take the year into account, only the day and months.
    Does anyone have an SQL-Query which can accomplish this?
    Btw: I'm using an Apache Derby database.
    Thx

    I was planning to use the BETWEEN function, but the problem is that the day of birth is stored in the database, so for example this could be a date in the year 1980. This year should be converted to the current year and then compared with the system date (difference of 30 or with the between function).

  • How to get the last day of the next month?

    Hi all.
    I need to get the last day of the next month. E.g. if the date is 20.03.2008 I need to get 30.04.2008.
    Is there any FM for it?
    TIA, Nikolai.

    hi Nikolai,
    pls. have a look athe following piece of code:
    PARAMETERS : p_date TYPE sy-datum.
    DATA : gv_res TYPE sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
    *   DAYS              = '0'
       months            = '2'
       start_date        = p_date
    IMPORTING
       result_date       = gv_res.
    ==> Now you have (gv_res) 2 months later as today
    gv_res+6(2) = '01'. ==> gv_res is first day of next-next month
    gv_res = gv_res - 1. ==> gv_res is last day of next month
    hope this helps
    ec

  • Can I get a Calendar event to repeat every 4 business days?

    I go to a school with a 4-day timetable; that is to say, classes repeat in the same order every 4 days. Is there any way to get events in Calendar to repeat every 4 business days?

    I just tested and here is what I get...

  • Can I buy an unlock iphone 5 in US now?  If I can, how many business days can I get it?

    Can I buy an unlock iphone 5 in US now?  If I can, how many business days can I get it?  Thank you!

    Yep, officially for sale now. Apple's online store shows it ships immediately, so should be in stock at just about every Apple store.

Maybe you are looking for