Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL: Function To find Last business day of the Month factoring in Holidays

SQL: Function To find Last business day of the Month factoring in Holidays

Scheduled Pinned Locked Moved Database
databasebusinesscode-review
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swoozie1
    wrote on last edited by
    #1

    We all have functions and code for business day calculations, or last day of the month calculations, ect... I am adding a caveat to this for Last business day of the month, not a holiday. I.e. (hypothetical), Last day is 12/31/2015, this is a Friday, however the company give this day off as a holiday so 12/30/2015 needs to be determined as the last business day of the month. I am looking at a couple of ways to approach this. 1) Calculate the Last Day of the month, Determine if it is not a Sat\sun, if is DateDiff to a business day, then take that date and compare to a Holiday table and adjust accordingly. 2) use a function that already exists for Last Business day of the month and then take that date and compare to a Holiday table and adjust accordingly. 3) some better what that I can not think of and no we can not use the XLeratorDB or what ever that is called. The out put I am looking for is just a DATE, the date of the very last company business day of the month.

    Thank you In advance! No reason to re-invent the wheel, just improve upon existing.

    L M 2 Replies Last reply
    0
    • S swoozie1

      We all have functions and code for business day calculations, or last day of the month calculations, ect... I am adding a caveat to this for Last business day of the month, not a holiday. I.e. (hypothetical), Last day is 12/31/2015, this is a Friday, however the company give this day off as a holiday so 12/30/2015 needs to be determined as the last business day of the month. I am looking at a couple of ways to approach this. 1) Calculate the Last Day of the month, Determine if it is not a Sat\sun, if is DateDiff to a business day, then take that date and compare to a Holiday table and adjust accordingly. 2) use a function that already exists for Last Business day of the month and then take that date and compare to a Holiday table and adjust accordingly. 3) some better what that I can not think of and no we can not use the XLeratorDB or what ever that is called. The out put I am looking for is just a DATE, the date of the very last company business day of the month.

      Thank you In advance! No reason to re-invent the wheel, just improve upon existing.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      swoozie1 wrote:

      use a function that already exists for Last Business day of the month

      Maybe somneone already wrote one, but there's no such thing built in, AFAIK. What a "week" or "weekend" is, is determined by your locale, and a company may have multiple of those. Holidays are even more complex, and tend to change rather frequently. Create a loop that inserts weekdays for your locale in a table; that way you have list with the weekends already eliminated. Next, delete every date in there that is mentioned in the holidays table (or join, or make a new table). Select the top result for that month. There's your last theoretical work-day.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      1 Reply Last reply
      0
      • S swoozie1

        We all have functions and code for business day calculations, or last day of the month calculations, ect... I am adding a caveat to this for Last business day of the month, not a holiday. I.e. (hypothetical), Last day is 12/31/2015, this is a Friday, however the company give this day off as a holiday so 12/30/2015 needs to be determined as the last business day of the month. I am looking at a couple of ways to approach this. 1) Calculate the Last Day of the month, Determine if it is not a Sat\sun, if is DateDiff to a business day, then take that date and compare to a Holiday table and adjust accordingly. 2) use a function that already exists for Last Business day of the month and then take that date and compare to a Holiday table and adjust accordingly. 3) some better what that I can not think of and no we can not use the XLeratorDB or what ever that is called. The out put I am looking for is just a DATE, the date of the very last company business day of the month.

        Thank you In advance! No reason to re-invent the wheel, just improve upon existing.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I use a view and a holiday table as I need to keep holidays for a number of countries/currencies. The view starts at the beginning of last year and goes for 10 years, arbitrarily picked by me, it has date part DayOfWeek so I can exclude weekends. It will be fairly simple to combine the two as Eddy suggested, fiddling with the filters/joins to get the last working sate.

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups