Here you go:

0001     CRT 'Enter a date (e.g. 1/9/2013)':
0002     INPUT date
0003     date = ICONV(date, 'D')
0004     mth = OCONV(date, 'DM')
0005     yr = OCONV(date, 'DY')
0006     first_of_month = ICONV(mth:'-1-':yr, 'D')
0007     day_of_week = OCONV(first_of_month, 'DW')
0008     FOR day = 1 TO 7
0009         BEGIN CASE
0010         CASE day_of_week = day
0011             target_day = first_of_month
0012         CASE day_of_week > day
0013             target_day = first_of_month + (day + 7 - day_of_week)
0014         CASE day_of_week < day
0015             target_day = first_of_month + day - day_of_week
0016         END CASE
0017         CRT OCONV(target_day, 'D'):' is the 1st ':OCONV(target_day, 
'DWA')'MCT':' of this month.'
0018         CRT OCONV(target_day+7, 'D'):' is the 2st 
':OCONV(target_day+7, 'DWA')'MCT':' of this month.'
0019         CRT OCONV(target_day+14, 'D'):' is the 3st 
':OCONV(target_day+14, 'DWA')'MCT':' of this month.'
0020         CRT OCONV(target_day+21, 'D'):' is the 4st 
':OCONV(target_day+21, 'DWA')'MCT':' of this month.'
0021         CRT
0022     NEXT day

Dan

On Wednesday, January 9, 2013 4:09:52 AM UTC-5, MRM wrote:
>
> Thanks a lot for the head -ups, really appreciate your input! Will the 
> same formula apply for example if i was looking for Tuesday, Wednesday, 
> Thursday or Friday?
>
> Thanks
>
> On Monday, January 7, 2013 11:59:20 PM UTC+3, Kevin Powick wrote:
>>
>>
>>
>> On Monday, 7 January 2013 10:46:00 UTC-5, Daniel Klein wrote:
>>>
>>>
>>> 0001     today = DATE()
>>> 0002     mth = OCONV(today, 'DM')
>>> 0003     yr = OCONV(today, 'DY')
>>> 0004     first_of_month = ICONV(mth:'-1-':yr, 'D')
>>> 0005     day_of_week = OCONV(first_of_month, 'DW')
>>> 0006     first_monday = first_of_month + (8-day_of_week)
>>> 0007     CRT OCONV(first_monday, 'D'):' is the 1st Monday of this month.'
>>>
>>>
>> That code actually doesn't work in all cases.  For example, try April 2013
>>
>> The following should give the 1st through 4th Mondays for any given month 
>> and year:
>>
>> TODAY = DATE()
>> YEAR  = OCONV(TODAY,'DY')
>> MONTH = OCONV(TODAY,'DMA')
>>
>> FIRST.OF.MONTH = ICONV('1':MONTH:YEAR,'D4')
>> DAY.OF.WEEK    = OCONV(FIRST.OF.MONTH,'DW')
>>
>> IF DAY.OF.WEEK = 1 THEN
>>    FIRST.MONDAY = FIRST.OF.MONTH
>> END ELSE
>>    FIRST.MONDAY = FIRST.OF.MONTH + (8 - DAY.OF.WEEK)
>> END
>>
>> FOURTH.MONDAY = FIRST.MONDAY + 21
>>
>> FOR MONDAY = FIRST.MONDAY TO FOURTH.MONDAY STEP 7
>>    CRT 'MONDAY = ':OCONV(MONDAY,'D2')
>> NEXT MONDAY
>>
>> --
>> Kevin Powick
>>
>

-- 
-- 
IMPORTANT: T24/Globus posts are no longer accepted on this forum.

To post, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/jBASE?hl=en



Reply via email to