Anyone know of an easy way to determine the day of week given a date in YYYYMMDD format? TIA, Chuck Ackerman
Anyone know of an easy way to determine the day of week given a date in YYYYMMDD format? TIA, Chuck Ackerman
Chuck, Use the SEARCH facility at the top of the forum screen. Look for: "Day of Week". This produced 50 hits. There are some good examples there. -bret
Search the www for Zeller's Congruence; No kidding... it can be coded easily even in RPG. I tested it against rexx dates over the 400 year cycle of the Gregorian calendar and it proved correct. It's also referred to by W. F. Schindler in his book. bobh
Determine a base date that you know the weekday of (Jan 1, 2000 is a Sat), use the SUBDUR opcode to find the number of days difference, divide by 7 and use the remainder with 0=Sat, 1=Sun....
That's good, if you know the DOWK for 01 Jan of every year and the day number of the date in question. bobh
John, "...and use the remainder with 0=Sat, 1=Sun..." And don't forget to first check if the remainder < zero, and if so, to add 7. This simple addition handles the cases where the request date is prior to the base date. Doug PS - Do you really want 0=Saturday? That seems unusual. Choose your base date to get the desired day to be a remainder of zero.
Hi, I solved this as follows. Write a CLP with these statements in it : CRTDTAARA DTAARA(&RTNLIB/TSBDAYNAME) TYPE(*CHAR) + LEN(15) TEXT('BACKUP : Temporary dataarea + for retrieval dayname') STRREXPRC SRCMBR(TSBDAYNAME) SRCFILE(&RTNLIB/TSBREXX) Then write a REXX-proc. with this in it : /************************************************** ****************/ /* Program-id : TSBDAYNAME */ /* Written by : Rob Baartwijk */ /* Description : Retrieve name of current day, store it in */ /* DTAARA TSBDAYNAM. */ /************************************************** ****************/ ARG RTNPARM RTNPARM=DATE('W') 'CHGDTAARA TSBDAYNAME' RTNPARM After the rexx-procedure has run you will find the name of the day in the dataarea(e.g. MONDAY, TUESDAY, etc.) No more calculations, no more startdates, no more exceptions ! HTH, Rob.
Search on CEEDAYS. There are three "CEE" APIs that are specifically designed for this purpose. Dave
Rob, Even simpler (for your requirement) which is different to Chuck's : RTVSYSVAL QDAYOFWEEK David
But David, that's cheating !!!!!! LOL! This systemvalue is not present on every version of OS/400 I believe. So I just came up with an alternative programming-approach. But of course, if someone is really looking for a solution, yours is the easiest/newest/simplest. G'Day, Rob.