Find out the day coinciding with date in iSeries

10 pts.
Tags:
iSeries
RPGLE Date Calculation
How to find out the Day for the particular date?

Ex- if today date is Jul 02, 2010 then the result is “Friday”

 



Software/Hardware used:
iSeries / RPGLE

Answer Wiki

Thanks. We'll let you know when a new response is added.

i know it’s RPGSQL, but i like this.

You pass the paramter Input Date of up to 10 characters and it returns the name of the day.

be sure to make the source member SQLRPGLE.

-sarge
*===================================================================== * Define Procedure and import/export paramters
*=====================================================================d DayOfWeek PR ExtPgm(‘DAYOFWEEK’)
d InPutDate 10a
d DayName 9a

d DayOfWeek PI
d InPutDate 10a
d DayName 9a
*===================================================================== * Names of the Day of the Week
======================================================================d DayNames ds
d 9a Inz(‘SUNDAY ‘)
d 9a Inz(‘MONDAY ‘)
d 9a Inz(‘TUESDAY ‘)
d 9a Inz(‘WEDNESDAY’)
d 9a Inz(‘THURSDAY ‘)
d 9a Inz(‘FRIDAY ‘)
d 9a Inz(‘SATURDAY ‘)
d NameOfDay 9a Dim(7) Overlay(DayNames)

//==================================================================== // Standalone field used to receive the number of the day of the week
//==================================================================== d DayNumber s 1s 0
//==================================================================== // Use SQL to find the name of the day for the date that was received
//==================================================================== //Free

Exec Sql
set :DayNumber = DayOfWeek(:InPutDate);

DayName = NameOfDay(DayNumber);

*InLr = *On;

Discuss This Question: 11  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    http://itknowledgeexchange.techtarget.com/itanswers/day-of-week-in-rpgle/ Here is a previous discussion on this topic Phil
    49,550 pointsBadges:
    report
  • TomLiotta
    Phil's link includes basic RPG coding for the CEEDATE API. That post also mentions the CEEDAYS API but doesn't show it. Both of those are ILE CEE Date and Time APIs. Here's some ILE CL code that uses those two APIs to turn a MMDDYY date into the day of the week. You can use it to study the behaviors, and the RPG code can guide how you'd use them:
    /* From an input date (MMDDYY), the day of the week is calculated   */
    /*   and returned to the caller...                                  */
    
    pgm    ( +
             &Date        +
             &DayWk       +
           )
    
       dcl   &Date          *char        6
       dcl   &DayWk         *char       10
    
       dcl   &RtnVal1       *int
    
    
       callprc      CEEDAYS      ( +
                                   &Date          +
                                   'MMDDYY'       +
                                   &RtnVal1       +
                                   *omit          +
                                 )
       callprc      CEEDATE      ( +
                                   &RtnVal1       +
                                   'Wwwwwwwww'    +
                                   &DayWk         +
                                   *omit          +
                                 )
    
    
    Exit:
    
       return
    
    endpgm
    Compile that as a procedure. For testing, also compile this ILE CL procedure:
    pgm
    
       dcl   &Date          *char        6   value( '010101' )
       dcl   &DayWk         *char       10   value( '*NONE     ' )
    
    
       rtvsysval   QDATE  rtnvar( &Date )
    
       callprc DAYWK      ( +
                            &Date        +
                            &DayWk       +
                          )
    
       sndusrmsg   msg( 'Date:' *bcat &Date *bcat 'Day:' *bcat &DayWk ) +
                     msgtype( *INFO ) tomsgq( *EXT )
    
       return
    
    endpgm
    You can use that as the entry procedure. It retrieves the QDATE value and passes it to the day-of-week proc. The day is returned as "Saturday", "Sunday", etc. Note that the CEEDAYS API in the example expects the 'MMDDYY' format. That should be adapted to whatever format is needed. Also note that the output format for the CEEDATE API is 'Wwwwwwwww'. If the desired day should be 'SATURDAY', then the format should be 'WWWWWWWWW' -- the API will adapt the case accordingly. Just a little experimentation should show how flexible the APIs are. Theey don't require SQL, and they can be used with any ILE language. Tom
    125,585 pointsBadges:
    report
  • Stiloabarthian
    select dayname(current_date) from sysibm/sysdummy1 14 July 2010 returns "Wednesday"
    175 pointsBadges:
    report
  • Stiloabarthian
    In RPGLE: exec sql (select dayname(current_date) into :variable from sysibm/sysdummy1);
    175 pointsBadges:
    report
  • TomLiotta
    exec sql (select dayname(current_date) into :variable from sysibm/sysdummy1); Somewhat shorter and more direct in SQLRPGLE:
      exec sql set :variable = dayname(current_date) ; 
    But as with any SQL+RPG, it requires the SQL Dev Kit to be installed. If performance is a serious concern, the CEE* APIs can run in 60% or less of the time that the shortest SQL will take. Tom
    125,585 pointsBadges:
    report
  • graybeard52
    Tom, Do you find the CEE API's to actually be faster than the SQL scaler function you suggested?. I would think that with no file I/O the SQL scaler would be very fast.
    3,115 pointsBadges:
    report
  • TomLiotta
    I would think that with no file I/O the SQL scaler would be very fast. Because the coding was so simple, I ran two tests. Not "scientific", but both were on the same system with no other users and the same system functions running in other subsystems. One test was ILE RPG that iterated directly around just the SQL SET statement; the other used the CL code but used a DOFOR loop around the two API calls. I was curious myself, especially since CL could potentially be slower as a natural result anyway. The CL was compiled as ILE. Both ran 10000 iterations and I ran a number of times to see if the first runs were slower than later runs. In both cases, the timings were comparable run-to-run. The APIs won consistently. I just ran one more test on both methods to see if results were similar tonight. Not quite as good as I averaged last night but tests were on my other system which is pretty memory constrained and quite a bit slower -- APIs at 31 Secs and SQL at 40 secs. Still, just over 75% of the time. I suppose I could get more methodical, but I would expect results only to go stronger in favor of the APIs. I'm pretty sure that IBM won't allocate as much development effort at making SQL work like a calculator, not when other groups are charged with that task. SQL does database; we shouldn't expect it to be the best at EVAL kinds of work, too. (Quite possibly, all it is really doing is acting as a wrapper for calling the APIs in any case!) Finally, for most sites, the SQL solution is more than good enough. I can be biased because some of our customers.are unusual to say the least. For example, a customer involved with the stock market has a fairly active system most of the day, but not to a degree that dwarfs lots of other sites. However, that first minute or two after the market opens...? You gotta watch every little CPU cycle if you want to sell a product there. You don't want to be the cause of a slowdown. So, some of my "detail points" tend to be somewhat academic. It won't matter if one method takes .003 secs and the other takes .004 secs. Then again, it can be a pleasant surprise when most of an app consists of components that all perform well. Tom
    125,585 pointsBadges:
    report
  • infiniumpro
    Oh in CL it got easier with a System Vaue: RTVSYSVAL Command with parameter QDAYOFWEEK:
    325 pointsBadges:
    report
  • TomLiotta
    RTVSYSVAL Command with parameter QDAYOFWEEK: The problem is that no matter what date you want the day-of-week for, the system value always returns it for the current date. That doesn't help much when you want to know now the day of week for 11/09/2011 and the next time you want it for 04/19/2009. Tom
    125,585 pointsBadges:
    report
  • graybeard52
    Tom, Interesting results. The only question I might have is if the call was from inside RPG in both cases ? That is, the overhead of calling CL API from RPG might have an effect. Seems like API's might win in either case. But unless I have to do millions of conversions, I would probably stick with using what's easier.
    3,115 pointsBadges:
    report
  • TomLiotta
    That is, the overhead of calling CL API from RPG ... CL API? The CEE* APIs aren't related to CL. RPG is perfectly comfortable with them, as shown in earlier posts. I suspect that I'm misunderstanding since I've seen plenty of your posts. So, can you clarify? Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following