Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:01:03+00:00 2026-06-15T09:01:03+00:00

I am trying to develop a scheduling application that needs to represent rules such

  • 0

I am trying to develop a scheduling application that needs to represent rules such as “this event occurs on the 2nd and 4th Wednesdays of the month” or “this event happens on odd-numbered Saturdays of the month (i.e. the 1st, 3rd, and 5th Saturday).

To that end, I need to write a function in T-SQL that takes a Date input and returns an integer representing which occurrence-in-month of the dayname falls on that date.

For example, if I send the function 2012 DEC 21, it would return 3, because December 21, 2012 falls on the 3rd Friday of that month. Given 2012 DEC 29, it would return 5, since December 29, 2012 falls on the 5th Saturday of that month.

I’d like to do this without recourse to a prepopulated calendar table. I might want to use the function to work with historical dates, e.g. to compute which Wednesday of the month July 16, 1958 was.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:01:04+00:00Added an answer on June 15, 2026 at 9:01 am

    Try this:

    SELECT ((DATEPART(d, @input) - 1) / 7) + 1
    

    We don’t care about the actual day of the week, just the number of days past the first of the month (which is the day value – 1). Then an integer divide by 7 to get the number of weeks past the first of the month, and finally + 1 to have it start at 1 instead of 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to develop a BlackBerry application that will show data from an
Trying to develop using MVVM: I have this Csla.PropertyStatus control that is created in
I am trying to develop a web application using ASP.net MVC 2. For that
I'm trying to develop a DHCP client application in java that can receive DHCP
I'm trying to develop an authentication plugin for an ASP.NET MVC3 application that would
Im trying to develop an application that should show a map using the Google
Im trying to develop service that starts by bootup receiver if the wifi or
im trying to develop an app for a win CE mobile device that downloads
I am trying to develop an application for my localhost on which I can
I am trying to develop an application to forward received SMS to a web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.