Are there alternate ways to determine the day of the week.
I have the following formula -
DayOfWeek = %Subst(('Sunday ' 'Monday ' 'Tuesday ' 'Wednesday' 'Thursday ' 'Friday ' 'Saturday ' ):(((%Rem(%Diff(%Date():%Date('1941-12-07'):*D):7)+1)*9))-8:9);
Software/Hardware used:
ASKED:
August 11, 2009 6:56 PM
UPDATED:
August 13, 2009 4:19 PM
Hi Satsho,
Can you please provide the programming language you’re using?
Thanks,
Jenny
Community Manager
Sorry, As/400, ILE RPG
I came up with this back in 2001 when I was learning to write sub procedures. It’s rather primitive but should be enough to get you started.
Thanks, Teandy – but I was looking to use BIF’s rather than actual RPG code.
Philpl1jb – Thanks, will try your code.
Appreciate your help. More ideas are welcome tho’.
Seems like a lot of work when you can do it in one line of code. Use the BIF or SQL
Then you don’t need all the rest of the code.
BTW: The 1751/1752 change from Julian to Gregorian won’t affect most of us, but I had to handle it when doing some ancestry stuff. They also changed the first day of the year from April 1 to January 1. Those who continued celebrating on April 1 were called “April Fools”. The IBM calcs do not take this change into consideration – it handles all dates as Gregorian.
Thanks Graybeard52 – unfortunately we are still in the process of moving to V6R1 and the DAYNAME function is not available in previous OS/400 versions.
This is the code for a service program I’ve used for a while:
H nomain D Dayofweek Pr 1p 0 D inputdate d D Dayname Pr 9 D inputdate d * ==================================================================== * Dayofweek - Calculate day of the week from input date * ==================================================================== P Dayofweek B Export D Dayofweek Pi 1p 0 D workdate d D Anysunday S d inz(d'1582-10-17') D Worknum S 7 0 D Workday S 1p 0 C workdate Subdur anysunday worknum:*d C worknum Div 7 worknum C Mvr workday C If workday <= *zero C Return workday + 7 C Else C Return workday C EndIf P Dayofweek E * ==================================================================== * Dayname - Return name of week day from given date * ==================================================================== P Dayname B Export D Dayname Pi 9 D workdate d D Namedata Ds D data 63 inz('Monday Tuesday WednesdayThur+ D sday Friday Saturday Sunday') D name 9 overlay(data:1) dim(7) C Return name(dayofweek(workdate)) P Dayname EI forget where I lifted the logic from, but it’s worked rather well.
>> unfortunately we are still in the process of moving to V6R1 and the DAYNAME function is not available in previous OS/400 versions <<
Sure it is. Back at least to v5R3. It’s a SQL statement. SQL doesn’t have to involve reading a file. I am at V5R4 and use it reguarly.
If you didn’t want to buy the SQL preprocessor, the following will work: DayOfWeek = %Subst((‘Sunday Monday Tuesday WednesdayThursday Friday Saturday ‘ ):(((%Rem(%Diff(%Date():%Date(’1899-12-31′): *D):7)+1)*9))-8:9); Make sure you have 9 bytes (letters or blanks) for each day name.Rico
I’m apparently missing something. The whole issue seems to be based on the %Date() that’s buried in the middle. Since that returns current system date, it seems that the question is “What’s the day-of-week today?” So just retrieve the QDAYOFWEEK system value. — Tom