Home > AS/400 Tips > iSeries programmer tips > Date calculation commands for AS/400
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Date calculation commands for AS/400


Kevin Ketzler, Contributor
07.15.2008
Rating: -3.75- (out of 5)


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


We received this tip regarding data calculations on the AS/400 that Kevin Ketzler thought would be helpful to System i users. If you have a tip, please send it to our editor's inbox.

As a consultant, over the course of many projects at different places, I periodically would have to calculate certain dates relative to a given date to determine reporting limits (e.g., month end, month begin). I also often had to determine the day of the week. So, I put together a little text file that first contained the calculations for these values. I have since converted the text file to contain procedures so that I can easily create a service program to perform the various date calculations.

h nomain option(*nodebugio:*srcstmt)


d getPriorMonthEnd...
d pr d
d pDate d const

d getPriorMonthBegin...
d pr d
d pDate d const

d getMonthBegin pr d
d pDate d const

d getMonthEnd pr d
d pDate d const

d getDayOfWeek pr 1p 0 Mon = 0 ... Sun = 6
d pDate d const

d isWeekDay pr n
d pDate d const

d isWeekEnd pr n
d pDate d const

p getPriorMonthEnd...
p b export
d getPriorMonthEnd...
d pi d
d pDate d const
/free
return pDate - %days(%subdt(pDate:*days));
/end-free
p getPriorMonthEnd...
p e

p getPriorMonthBegin...
p b export
d getPriorMonthBegin...
d pi d
d pDate d const
/free
return getMonthBegin(pDate - %months(1));
/end-free
p getPriorMonthBegin...
p e

p getMonthBegin b export
d getMonthBegin pi d
d pDate d const
/free
return getPriorMonthEnd(pDate) + %days(1);
/end-free
p getMonthBegin e

p getMonthEnd b export
d getMonthEnd pi d
d pDate d const
/free
return getPriorMonthEnd(pDate + %months(1));
/end-free
p getMonthEnd e

p getDayOfWeek b export
d getDayOfWeek pi 1p 0 Mon = 0 ... Sun = 6
d pDate d const
/free
return %rem(%diff(pDate:d'0001-01-01':*days):7);
/end-free
p getDayOfWeek e

p isWeekDay b export
d isWeekDay pi n
d pDate d const
/free
return getDayOfWeek(pDate) < 5;
/end-free
p isWeekDay e

p isWeekEnd b export
d isWeekEnd pi n
d pDate d const
/free
return getDayOfWeek(pDate) > 4;
/end-free
p isWeekEnd e

ABOUT THE AUTHOR: Kevin C. Ketzler is a designer, analyst, and project lead for IBM Solutions Practice at Affiliated.

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
iSeries programmer tips
Using SQL on System i to create multicolored comment lines
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Coloring source lines with COBOL and using a shortcut from within PDM
There is very little RPG on System i can't do: From RPG nay to RPG yay!
Using SQL on System i to color source code and inline comments
Controlling spool files with APIs
System i document management tips
Selective SPOOLFILE copy to CSV files and e-mail
System i Resume Building 101

iSeries programming commands
Monitoring escape messages and using RCVMSG for diagnostic messages
iSeries application display subfiles with other program windows
Creating a user profile from a file
DSPPGMREF (Display Program Reference)
DSPPGM (Display Program)
DSPFD (Display File Description)
DSPPTF (Display PTF)
Top 10 iSeries commands
WRKACTJOB (Work with Active Jobs)
WRKOBJLCK (Work with Object Locks)
iSeries programming commands Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Quiz: iSeries (AS/400) Commands  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts