BussinesDaysToCalendarDays

  • Comments posted to this topic are about the item BussinesDaysToCalendarDays

  • Alter Function GetCalanderDaysFromBusinessDays (@BusinessDay int)

    Returns Date

    as

    Begin

    Declare @CalanderDays int

    Declare @FinalDate Date

    Set @CalanderDays = ((@BusinessDay/5)*7) + (@BusinessDay % 5)

    Set @FinalDate = DateAdd(Day, @CalanderDays, GetDate())

    Return @FinalDate

    End

  • Hi Parajuli,

    I like your formula, is neat. But i found it does not produce a correct result for one case.

    Look, if the bussinesweek is Monday to Friday, and I run this procedure in a wednesday setting the parameter @BussinesDay = 4, the result should be that the final date is next Monday ( Wednesday 1, Thursday 2, Friday 3, Monday 4), but the below query tells me that final date is Sunday. You see anything missplaced in my test?

    DECLARE @BusinessDay INT;

    SET @BusinessDay = 4

    Declare @CalanderDays int

    Declare @FinalDate Datetime

    Set @CalanderDays = ((@BusinessDay/5)*7) + (@BusinessDay % 5)

    Set @FinalDate = DateAdd(Day, @CalanderDays, '2012-07-11') -- Wednesday

    select @FinalDate, datename (Weekday,@finalDate)

  • Not sure which one works...but h.parajuli can spell BUSINESS correctly unlike Adrian.

  • But unfortunately h.parajuli cannot spell CALENDAR.

  • Ha ha i haven't noticed it. Parajuli and I have some homework to do =).

  • Thanks for the script.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply