D
DavidObeid
Can anyone help me write a formula to find the date of the second sunda
in a given month?
Thanks in Advance,
Dav
in a given month?
Thanks in Advance,
Dav
Bob Phillips said:David,
Assuming you have a date in A1, this gives the 2nd Sunday of that date
=DATE(YEAR(A1),MONTH(A1),1)+MOD(8-WEEKDAY(DATE(YEAR(A1),MONTH(A1),1)),7)+7
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
Can anyone help me write a formula to find the date of the second sunday
in a given month?
Thanks in Advance,
Dave
....Bob Phillips said:Assuming you have a date in A1, this gives the 2nd Sunday of that date
=DATE(YEAR(A1),MONTH(A1),1)+MOD(8-WEEKDAY(DATE(YEAR(A1),MONTH(A1),1)),7)+7
....Dana DeLouis said:I believe this is just another option....
=EOMONTH(A1,-1)-WEEKDAY(EOMONTH(A1,-1))+15
Thank you very much!
Can I bother you further to inquire as to the logic. I will tell you where
I got to, and then you can correct or add as the case might be?
Let's use 15 March 2004 as an example.
=A1-DAY(A1)-WEEKDAY(A1-DAY(A1),2)+15
A1-DAY(A1) gives the last day of the prior month. 29 Feb 2004.
WEEKDAY(A1-DAY(A1),2)...is the weekday of the last day of the prior month,
using Monday as 1. So in our case, we have Sunday or 7.
Questions:
1) Why did you use the "2" parameter? Guess: you wanted the Monday to be
one, just as for the Sunday example, Sunday was 1.
2) Would the symmetry of this example break down if you wanted the 2nd
Thursday because you cannot set Thursday to 1?
A1-DAY(A1)-WEEKDAY(A1-DAY(A1),2)
Yields the 22nd (=29-7) of February. You are always going to "back-up" into
the previous month to a Sunday where you have a full week remaining in prior
month? Now you add 15.
2nd Example:
=DATE(YEAR(A1),MONTH(A1),15)-WEEKDAY(DATE(YEAR(A1),MONTH(A1),6))
I understand the end result of the equation, though I do not understand why
you started off with the 15th of the current month. So I am missing step 1.
I suspect once I get a slight push, your solution will rapidly make sense.
But right now, I am stumped.
The reason for asking my questions is to better my understanding. Like most
everything else, a bit of practice always helps.
Thank you so much Peo.
Best regards,
Kevin
Kevin Stecyk said:David,
I adapted Bob's solution to your "Monday" challenge.
=DATE($A$2,C43,1)+MOD(9-WEEKDAY(DATE($A$2,C43,1)),7)+7
A2= 2004
C43=4
12 April 2004 is the answer.
Let me explain Bob's solution.
The first part of date is easy. It is just the first day of the month.
The Mod portion
If you start with Sunday being 1, the following Monday is 9. Subtract Day
of the Week for the first day. In our example, the first of the month is
Thurs and thus day of week is 5. The modulo of (9-5)/7 is 4. In other
words, 4 is the remainder. This means you need another 4 days to get to the
first Monday. And then add 7 days to get to the second Monday.
Let's look at March 2004.
The first day of the week is Monday, which is a 2. The modulo of (9-2)/7 is
0. In other words, you need 0 days to get to the first Monday. So just add
another 7 days to get to the second Monday.
Bob's solution to me is cleaner and more elegant than my solution and I
encourage you to use Bob's solution.
Hope this helps.
Regards,
Kevin
DATE(YEAR($A$2),MONTH(C41),1)+7,DATE(YEAR($A$2),MONTH(C41),1)+15-WEEKDAY(DATDavidObeid said:Dear Kevin,
I tried using the formula you gave me to find a different occurance of
a day in a month (eg the 2nd Monday) and I am having troubles getting
it to work.
here is what you gave me (modified to fit where data is in my
spreadsheet):
=IF(WEEKDAY(DATE(YEAR($A$2),MONTH(C41),1))=1,DATE(YEAR($A$2),MONTH(C43),1)+7,DATE(YEAR($A$2),MONTH(C43),1)+15-WEEKDAY(DATE(YEAR($A$2),MONTH(C41),1)))
and it works fine!
here is what I tried to get it to find the 2nd monday:
=IF(WEEKDAY(DATE(YEAR($A$2),MONTH(C43),1))=2,
Bob Phillips said:Kevin,
The basic formula gives the first occurrence of Sunday. The second, third
etc. occurrence is simply achieved by adding 7, 14, etc to that formula
When I looked at this, I thought about the day of the week problem, and I
came up with this to get the first day of the month
Sun
=DATE(YEAR(A1),MONTH(A1),1)+MOD(8-WEEKDAY(DATE(YEAR(A1),MONTH(A1),1)),7)
Mon =DATE(YEAR(A1),MONTH(A1),1)+MOD(8-WEEKDAY(DATE(YEAR(A1),MONTH(A1),7)),7)=DATE(YEAR(A1),MONTH(A1),1)+MOD(8-WEEKDAY(DATE(YEAR(A1),MONTH(A1),5)),7)Tue
=DATE(YEAR(A1),MONTH(A1),1)+MOD(8-WEEKDAY(DATE(YEAR(A1),MONTH(A1),6)),7)
Wed
etc.
Problem here is that Help only gives 2nd argument values of 1,2,3. SO
although it seems to work, it may not be supported going forward.
What I decided to do, as this is such a frequent request, is to knock up a
UDF that does it for any occurrence, including last, and any day,.
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
(9-2)/7Kevin Stecyk said:David,
I adapted Bob's solution to your "Monday" challenge.
=DATE($A$2,C43,1)+MOD(9-WEEKDAY(DATE($A$2,C43,1)),7)+7
A2= 2004
C43=4
12 April 2004 is the answer.
Let me explain Bob's solution.
The first part of date is easy. It is just the first day of the month.
The Mod portion
If you start with Sunday being 1, the following Monday is 9. Subtract Day
of the Week for the first day. In our example, the first of the month is
Thurs and thus day of week is 5. The modulo of (9-5)/7 is 4. In other
words, 4 is the remainder. This means you need another 4 days to get to the
first Monday. And then add 7 days to get to the second Monday.
Let's look at March 2004.
The first day of the week is Monday, which is a 2. The modulo ofDATE(YEAR($A$2),MONTH(C41),1)+7,DATE(YEAR($A$2),MONTH(C41),1)+15-WEEKDAY(DATDATE(YEAR($A$2),MONTH(C43),1)+7,DATE(YEAR($A$2),MONTH(C43),1)+15-WEEKDAY(DATis
0. In other words, you need 0 days to get to the first Monday. So just add
another 7 days to get to the second Monday.
Bob's solution to me is cleaner and more elegant than my solution and I
encourage you to use Bob's solution.
Hope this helps.
Regards,
Kevin
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.