What date was the 1st Tuesday of last month . . .
John Webster
john.webster@clear.net.nz
Mon, 13 Nov 2000 20:29:41 +1300
Hi Richard
Given X as the starting date...
(a) Change the day portion to 01 to get the first of the current month
>define A date = (dateextract(X,year)*10000) + (dateextract(X,month)*100) +
01
(b) Use the DAYS function to get the number of days and
Subtract 1 to get the last day of the previous month in days (This caters
for leap years or going back into a previous year etc)
>define B num*8 = days(A) - 1
(c) Use the DATE function to convert it back to a date
>define C date = date(B)
(d) Change the day portion to 01 to get the first day of last month
>define D date = (dateextract(X,year)*10000) + (dateextract(X,month)*100) +
01
(e) Use the DAYS function to get the number of days of the first of the
month you want
>define E num*8 = days(D)
(f) Use the MOD function to divide the answer by 7 and give the remainder.
>define F = mod(E,7)
(g) Now, here's where my memory fails me and I haven't got my manuals
handy...
If F is zero then the day you've got is a Sunday (or maybe a Monday - you'll
need to check this one yourself! whatever, the principle is the same - lets
assume it's a Sunday). If F is 2 then it's a Tuesday and you need go no
further. If F isn't 2 then you need to add a number of days to get to the
first Tuesday. There's a cleverer way of doing it, but...
>define G = 2 if F = 0 else 1 if F = 1 else 0 if F = 2 else 6 if F = 3 else
5 if F = 4 else 4 if F = 5 else 3 if F = 6
>define H date = days(E + G)
Now this isn't the most elegant solution, but you can test it at each step
> report X A B C D E F
and check it against a calendar...
John W
----- Original Message -----
From: "Latimer, Richard" <richard.latimer@airways.co.nz>
To: <powerh-l@sphere.swau.edu>
Sent: Monday, November 13 2000 09:08
Subject: What date was the 1st Tuesday of last month . . .
> Greetings listers!
>
> I have been asked to produce a report to run (as part of a month end batch
> job) on the third working day of each month that supplies data for the
first
> TUESDAY of the preceding month and another that supplies data for the
> subsequent weekend.
>
> The reports themselves exist and only require changes to the choose
> statements and we already have a technique to supply updated 'chooses' to
> reports which I will reuse:
>
> exe report1 ; disk output to 1 line file " choose date <date 1> "
> exe report 2 nogo
> use <output of report 1>
> go
>
>
> My problem is an easy way to determine the date of the first Tuesday in
the
> preceding month based on either the system date OR I have available, in a
> control file, the end date of the reporting month.
>
> Thanks in advance!
>
>
> Richard Latimer
> Wellington MIS Manager
> Airways New Zealand
> DDI + 64 4 471-4744
> FAX + 64 4 471-0395
> --------------------------------------------------------------------------
--
> -----------
> The opinions expressed are my own, well most of them are mine.
> OK some of the opinions are mine . . .
> At least the opinions expressed are not those of my employer.
> I have high hopes of getting an opinion in the near future!
> --------------------------------------------------------------------------
--
> -----------
>
> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
=
> Subscribe: "subscribe powerh-l" in message body to
majordomo@lists.swau.edu
> Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
> This list is closed, thus to post to the list, you must be a subscriber.
>
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.