Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine week in a month
Message
 
 
To
24/08/2017 18:42:12
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01653700
Message ID:
01653710
Views:
31
>>>Hi,
>>>
>>>I am trying to create a function that will return the week number in a month, by any date of Monday.
>>>
>>>For example, the date "08/21/2017" (in American system) it would be 3rd week (in August). The week has to have Monday. So this month (August) the first week is the week of August 7, August 14 is week 2, August 21 is week 3, and August 28 is week 4.
>>>
>>>My code is very convoluted/complicated and I am sure there is a better way.
>>>
>>>TIA
>>
>>Ok. Here is my version:
>>
>>*--- dMonday is any Monday of the year
>>DO CASE 
>>	CASE MONTH( dMonday - 7 ) <> MONTH( dMonday )
>>		nMonthWeek = 1
>>	CASE MONTH( dMonday - 14 ) <> MONTH( dMonday )
>>		nMonthWeek = 2
>>	CASE MONTH( dMonday - 21 ) <> MONTH( dMonday )
>>		nMonthWeek = 3
>>	CASE MONTH( dMonday - 28 ) <> MONTH( dMonday )
>>		nMonthWeek = 4
>>	OTHERWISE 
>>		nMonthWeek = 1
>>ENDCASE 
>>
>>RETURN (nMonthWeek)
>>
>>
>>Do you see that it could be simpler?
>
>
>Well, let me beat the horse Dragan already targeted from another angle:
>there are months with more than 28 days, which your code will press into 4 weeks. Some weeks of those I'd prefer not to work but count as holiday weeks as they have more than 7 days ;-)

You are lucky that you only have to work 35 hours a week :). In American, we work 24/7 :).
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform