# Thread: Determine Day of Week in RPG

1. Guest.Visitor Guest

## Determine Day of Week in RPG

Anyone know of an easy way to determine the day of week given a date in YYYYMMDD format? TIA, Chuck Ackerman

2. B.Myrick Guest

## Determine Day of Week in RPG

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

3. Guest.Visitor Guest

## Determine Day of Week in RPG

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

4. Guest.Visitor Guest

## Determine Day of Week in RPG

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....

5. Guest.Visitor Guest

## Determine Day of Week in RPG

That's good, if you know the DOWK for 01 Jan of every year and the day number of the date in question. bobh

6. D.Handy Guest

## Determine Day of Week in RPG

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.

7. Guest.Visitor Guest

## Determine Day of Week in RPG

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.

8. Senior Member
Join Date
Dec 2007
Posts
3,908

## Determine Day of Week in RPG

Search on CEEDAYS. There are three "CEE" APIs that are specifically designed for this purpose. Dave

9. Guest.Visitor Guest

## Determine Day of Week in RPG

Rob, Even simpler (for your requirement) which is different to Chuck's : RTVSYSVAL QDAYOFWEEK David

10. Guest.Visitor Guest

## Determine Day of Week in RPG

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.