DayofWeek of Month Dilemma

 

Hi,

I am having this problem that I can't solve for 2 weeks.

I want to check if the current day is the first Sunday of the month. I seem to can't reconcile my code to do this.

I need a function basically to tell me the current Day is the DayofWeek of the Month. In others words, for example, is the current day checkable to see if its the last fourth Wed of the Month or is it the second Tues of month and so forth.

I would like some kind of efficient of to that.

THanks in advance for your help.

-john

 
//#######################################################################
//#######################################################################
int Week_Of_Month(){
//#######################################################################
//#######################################################################
int Week_Of_Month;
int Day_Month=TimeDay(Time[0]);
if(Day_Month<=7)Week_Of_Month=1;
if(Day_Month<=14 && Day_Month>7)Week_Of_Month=2;
if(Day_Month<=21 && Day_Month>14)Week_Of_Month=3;
if(Day_Month<=31 && Day_Month>21)Week_Of_Month=4;
//#######################################################################
//#######################################################################
return(Week_Of_Month);}
//#######################################################################
//#######################################################################
 
ubzen:


your code is not going to work for months that start on Wed or on Fri or months that don't start on Sunday.

 

Well I'm a newbie, and came up with that off the top of my head.

I'm thinking if the first day of the month is Wednesday.  And you wanting to know if it's the first Wednesday. Then Day_Month=1 and Week_Of_Month=1. So it's the 1st Wednesday. When the 2nd Wednesday comes along it's going to be Day_Month=8 and Week_Of_Month=2. The function returns Week_Of_Month so this is the 2nd Wednesday and So on. I could be wrong tho if that's not what you're looking for.

 
its not going work and become inaccurate for the next weeks days that are before Wed.
 
rammer202:

Hi,

I am having this problem that I can't solve for 2 weeks.

I want to check if the current day is the first Sunday of the month. I seem to can't reconcile my code to do this.

I need a function basically to tell me the current Day is the DayofWeek of the Month. In others words, for example, is the current day checkable to see if its the last fourth Wed of the Month or is it the second Tues of month and so forth.

I would like some kind of efficient of to that.

THanks in advance for your help.

-john


Weren't you looking for the 1st, 2nd, 3rd and 4th. particular day of the month? Example 1st Wednesday or 2nd Wednesday or 3rd Wednesday and 4th Wednesday? If however you wanna know what Sunday-Saturday week the day falls in then that's a different question than what i read.

 

The answer to your problem is upon you deciding what month you want the day to belong to whenever the week split between 2 different months. Example Wednesday is the 1st of the month. You have to decide if it belongs to the new month or the old month. If your answer is old month then you wanna start your code out be singling out the Sundays. Good luck.

 

I don't know your culture. But a Wed of the new month is the first week of the new month. your code doesn't work and become inaccurate for the 2nd week's Tues (6th day) and Mon (5th Day).

Do you see the problem with your code?

 
WEEK
S
M
T
W
T
F
S
week 1



1
2
3
4
week 2
5
6
7
8
9
10
11
week 3
12
13
14
15
16
17
18
week 4
19
20
21
22
23
24
25
week 5
26
27
28
29
30
31

 

Red=1st Days, Blue=2nd Days, Green=3rd Days, Yellow=4th Days and Purple=5th Days (Code didn't cover, can be fixed) .

If my boss told me to take the 1st Wednesday in this month off, I'd would think he means Wednesday the 1st. If he said take the 1st Monday off, I'd think he means Monday the 6th. 1st Tuesday then Tuesday the 7th.

If he said take the 2nd Wednesday of the month off, I think Wednesday the 8th. 2nd Monday = Monday the 13th. Second Tuesday = Tuesday the 14th. This is what I understood your question to be.

 

If however, you're saying Tuesday the 7th is NOT the 1st Tuesday in the Month because it within the Week 2 then we're on different wave length. The variable Week_Of_Month Does_Not return actual Week of the Month. Week of month 1 means 1st Seven Days. 2 = Second set of Seven Days and so on. It's trying to answer your" is it the second Tues of month" when it equals 2.

 

i see what you are saying...

 
rammer202:

But a Wed of the new month is the first week of the new month


ubzen posted an epic response, to which I have little to add, but I would say based even on just this statement alone there appears to be some confusion on your part regarding what the first week of a month is meant to entail.

If a new month starts on a Thursday, Friday or Saturday then the first Sunday, first Monday, first Tuesday, and first Wednesday would all be in the second week of the month, guaranteed, no cultural differences to contend with.