473,586 Members | 2,682 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NOT Particular Weekday in a Month but the opposite

I want my code to tell me that (today) April 12th is the second
wednesday of the month. And only thing I can find is the function to
tell me what date belongs to the 2nd day in a given month and year.

Please help
regards
ScuBart

Apr 12 '06 #1
14 2122
you'd have to write a function to do it. Do something like...

1. get the day of the first day of the month.
2. find the number of weeks between the two dates
3. then from that you should be able to get the number of Wednesdays or
whatever.

Look up DateAdd, DateDiff, MOD, and that should do it.

Apr 12 '06 #2
Plant this code in a standard code module. Place your mouse cursor
inside of someSub(). Press the F5 key. This will display the given day
which the built-in Date() function returns and if it is the 1st, 2nd,
3rd... occurence of that day in that month. You can use any date value
for the argument.

'------------------------------------------------------
Sub someSub()
Dim d1 As Date, arrSuffix As Variant
arrSuffix = Array("", "1st", "2nd", "3rd", "4th", "5th")
d1 = Date '--d1 can be any date you want: d1=#3/13/06#
Debug.Print arrSuffix(DayOf MonthCount(d1)) & " " & _
WeekdayName(Wee kday(d1))
End Sub
Function DayOfMonthCount (d1 As Date) As Integer
Dim i As Integer, j As Integer, k As Integer, d2 As Date
d2 = d1 - Day(d1) + 1 '--go to beginning of d1
k = 0
'--get count of days in the month of d1
j = Day(DateAdd("m" , 1, d1) - Day(DateAdd("m" , 1, d1)))
For i = 0 To j
'--get count of times the d1 day occurs in the month of d1
If Weekday(d2 + i) = Weekday(d1) Then k = k + 1
If d2 + i > d1 Then Exit For
Next
DayOfMonthCount = k
End Function
'----------------------------------------------------

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Apr 12 '06 #3
Rich,
I may need a little bit of help. I've put the code in a module and from
the Visual basic Editor I can step through it. I've put in a msgbox to
see what the result is and it says that today is the second friday
(instead of thursday) but that has something to do with monday being my
first day and normal is sunday.

Now; when I open een a form I display the date, the weeknumber and in a
subform the actions that belong to this given date or day.

We have actions on every monday and actions for the first monday of the
month (and wednesdays and thursday to). So When I open the form I'll
have to caal the function to put in to a text box for example if this
is the second monday (or wednesday or thursday).

Can you provide me with extra hints!
Thanks so far

Apr 13 '06 #4
Rich P schreef:
Function DayOfMonthCount (d1 As Date) As Integer


Using integer division operator "\", the code can be s
implified a little:

DayOfMonthCount = 1 + (Day(d1) - 1) \ 7

--
Paul
Apr 13 '06 #5
Sometimes people whoe are an expert in things are very cryptic for
people who are reasonable new in this stuff.

Paul, I appreciate the help but I have no idea what you mean.

On opening my form I've got in a field "second thursday" and thats what
i wanted. Now the rest of this challenge!!

Apr 13 '06 #6
Divit
On opening my form I've got in a field "second thursday" and thats what
i wanted. Now the rest of this challenge!!


My code only replaces Rich's version of the calculation.
I'm not shure what it is that your trying to do.
Maybe you want to know the exact date of the second
thursday in a certain month of a certain year?
Apr 13 '06 #7
No, as I explained I want to know what "day" today is. It's april 13th
and more important it's the second thursday of the month. I want to
build an application to do my planning. We have actions that occur
every monday for example but also actions in even-weeks on wednesday.

So I have to determine what "day" todat is.

I solved the "second thursday of april" problem and ofcourse the day
and the weeknumbers where no problem. Now I have to figure how to
combine my 2 tables. 1 with actions and the other with occurences.

Hope you got it.
Bart

Apr 13 '06 #8
Divit schreef:
No, as I explained I want to know what "day" today is. It's april 13th
and more important it's the second thursday of the month. I want to
build an application to do my planning. We have actions that occur
every monday for example but also actions in even-weeks on wednesday.

So I have to determine what "day" todat is.

I solved the "second thursday of april" problem and ofcourse the day
and the weeknumbers where no problem. Now I have to figure how to
combine my 2 tables. 1 with actions and the other with occurences.

Hope you got it.


Well ... let me rephrase.

One table specifies for each action a pattern of calendar dates -
monday of an even week, 2nd thursday of a month, etc.

Given a date range FromDate..ToDat e you can derive a
planning of actions on actual dates in that range.
That's what your after, or?

What 2nd table do you mean? Some technical solutions
use a table of all dates in the range. Is that the one?
Apr 13 '06 #9
A little fun function for morning coffee.

Public Function Whatever(ByVal d As Date) As String
Dim a As Variant
a = Array("1st", "2nd", "3rd", "4th", "5th", "6th", "7th")
Whatever = a((Day(d) - 1) \ 7) & " " & WeekdayName(Wee kday(d),
True, vbSunday)
End Function

Works for April 2006. Not tested otherwise.
Done in Access 2003. Not sure in what version the WeekdayName function
was given to us. Second Parameter ("True") of WeekdayName function
determines abbreviations or full name.

Apr 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
11244
by: dr. zoidberg | last post by:
Hello, I have this: Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to do is to associate days with its current week dates, for example: Mon (05.01.2004); Tue (06.01.2004); and so on. TNX
2
6606
by: David Morgan | last post by:
Hi Hopefully the subject says it all. Given a weekday, (1 to 7) and an occurrence with in a month, (1 to 4), I need to ascertain the date on which it first occurs in any given month and year. For example, what is the date of the third Tuesday in October 2004. Has anyone done this before? Would be grateful for some assistance.
2
1543
by: Chumley the Walrus | last post by:
I can't locate a weekday function in asp.net, whereas I just want to grab the weekday associated with a given date. I'm using this date format {0:MM/dd/yyyy} in references in my code, just need to do something like : dim myweekday myweekday = weekday({0:MM/dd/yyyy}) response.write (myweekday) thanks
0
1065
by: Chumley the Walrus | last post by:
I have a datalist, and I need to display the appropriate weekday contigent upon the date that exists in my 'showdate' record (which is a datetime datatype): <% if weekday(Container.dataItem("showdate")) = 2 then response.write "monday" end if %> ....gives me a "Container is not declared" error
1
2021
by: Kd | last post by:
I am currently using a form with Weekdays Mon Tues Wed Thur Fri This is generated by a table that the days are being entered manually I would like to create a form that the days updated themselves by 7 days each time a new record is opened. Any and all thought are appreciated
4
6696
by: dgmoore | last post by:
I've hit a snag - I know this is easy, but the logic is escaping me. I need to set criteria in a query to find dates in a date field that lie between Tuesday of the current week and Tuesday of the previous week. Any suggestions would be appreciated. Thanks Dave
0
1621
by: Rudi Hausmann | last post by:
Hi! I have a column with a date. In another column I want to show the weekday of this date. I have following code: <asp:BoundField DataField="myDate" HeaderText="WeekDay" SortExpression="weekday" DataFormatString="{0:dddd}" HtmlEncode="False" ApplyFormatInEditMode="True" /> <asp:BoundField DataField="myDate" HeaderText="Day"...
4
3841
by: AdrianGawrys | last post by:
Can someone tell me why this query works: SELECT WeekdayName(Weekday(#17/02/2007#)-1) AS and this one doesnt SELECT WeekdayName(Weekday(#18/02/2007#)-1) AS what I am trying to achieve is to get weekday from date obviously. a Appreciate any help
9
7822
by: Dave | last post by:
What is the C# Equivalent to VB's Weekday function? I'm trying to convert this: Select Case Weekday(CurrentDate) Case 1 ' Sunday WKG = CurrentDate Case 2 ' Monday WKG = CurrentDate + 6 Case 3 ' Tuesday WKG = CurrentDate + 5
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.