473,387 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calculating 2nd Thursday after 1st Tuesday in a Month

I need to create a database that will be used to schedule patches. Many of our patches happen on the 1st Saturday of the month, but some happen on the 2nd Thursday after the 1st Tuesday every month.

Ive been attempting to use the DATEPART and WEEKDAY functions but without success. Figuring out the 1st Saturday shouldnt be to hard, even if I havent managed to figure that out just yet, but the other is beyond my experience.
Mar 29 '08 #1
4 5160
PianoMan64
374 Expert 256MB
I need to create a database that will be used to schedule patches. Many of our patches happen on the 1st Saturday of the month, but some happen on the 2nd Thursday after the 1st Tuesday every month.

Ive been attempting to use the DATEPART and WEEKDAY functions but without success. Figuring out the 1st Saturday shouldnt be to hard, even if I havent managed to figure that out just yet, but the other is beyond my experience.
Here's your answer:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function FirstSatOfMonth() As Date
  3.  
  4.     For x = 0 To 6
  5.         If Weekday(DateSerial(Year(Date), Month(Date), 1) + x, vbUseSystemDayOfWeek) = vbSaturday Then
  6.             FirstSatOfMonth = DateSerial(Year(Date), Month(Date), 1) + x
  7.         End If
  8.     Next x
  9. End Function
  10.  
  11. Function SecondThursdayafterFirstTuesday() As Date
  12.     For x = 0 To 6
  13.         If Weekday(DateSerial(Year(Date), Month(Date), 1) + x, vbUseSystemDayOfWeek) = vbTuesday Then
  14.             SecondThursdayafterFirstTuesday = DateSerial(Year(Date), Month(Date), 1) + x + 9
  15.         End If
  16.     Next x
  17. End Function
  18.  
  19.  
Mar 29 '08 #2
Wow! Thanks for the quick response. Its midnight here, didnt think anyone would reply until tomorrow morning. You rock!
Mar 29 '08 #3
I used the information you gave me to create 33 functions. They all work perfect now, but Ive run into another problem.

The following is a quick example of what I am trying to do:

---
Private Sub MonthCombo_AfterUpdate(Cancel As Integer)

[test] = First_Saturday()

End Sub
---

Basically when the user changes the month in the form header it will update all the patch windows using their particular function.

First_Saturday() is in a module named DateCalculation.

Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.

I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.

This is the following error I get as the AfterUpdate runs...

The expression After Update you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
Mar 29 '08 #4
PianoMan64
374 Expert 256MB
I used the information you gave me to create 33 functions. They all work perfect now, but Ive run into another problem.

The following is a quick example of what I am trying to do:

---
Private Sub MonthCombo_AfterUpdate(Cancel As Integer)

[test] = First_Saturday()

End Sub
---

Basically when the user changes the month in the form header it will update all the patch windows using their particular function.

First_Saturday() is in a module named DateCalculation.

Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.

I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.

This is the following error I get as the AfterUpdate runs...

The expression After Update you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
The sub routine that you sent, I'm assuming the [Test] is a control on the current form this sub is in?

If so, simply do the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub MonthCombo_BeforeUpdate(Cancel As Integer)
  3.  
  4.   me.Test = First_Saturday()
  5.  
  6. End Sub
  7.  
Hope that helps,

Joe P.

p.s. The AfterUpdate Event doesn't support (Cancel as Integer). That's why you were getting the error.
Mar 30 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paolo | last post by:
I have a form on which I have a field named DOB which stores the client's date of birth (mm/dd/yyyy). I would like that when users open the form, a message should alert if that person is over...
5
by: Mark Hall | last post by:
Our reporting cycle goes from Wednesday to Wednesday an I need to calculate the next Wednesday after the update was received. If an upate comes in on say a Tuesday (eg 20 Jan 04) then I want a...
3
by: Paul Mendez | last post by:
Performance_Date SumOfBudget_NOI CurrYTD_BudgetNOI_Total 1/1/2004 $4,184,626.00 ? 2/1/2004 $4,484,710.00 ? 3/1/2004 $4,537,424.00 ? 4/1/2004 ...
2
by: Gustavo G. Rondina | last post by:
It is possible to caclulate every year's easter using simple mathematical operations. Here is a code that does the trick: http://www.brlivre.org/c/easter.c I found the math scheme in an...
7
by: Jason | last post by:
I've created a service in c# that performs a certain action at a particular day of the month I want this service to kick off the action every third Tuesday of the month. How would I set the...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
HI I have a stored procedure that returns data with a date field in the form of a DateTime type. I need to place data in variables based on days of the week starting with the first thursday of the...
5
by: cbalian | last post by:
I am looking for a TSQL code that would calculate a specific date each month that varies based on the following condition: I need the result that would return the date of the Thursday after the...
2
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.