TATWORTH
0 pts. | May 13 2005 5:52AM GMT
Whilst some languages (or environments such as .NET) have such functions, your problem breaks down into the following steps
1) Decompose the date into YYYY, MM, DD components
2) Add 2 to MM
3) If MM > 12 then YYYY = YYYY + 1, MM = MM - 12
4) Re-assemble the date to give the first of the month following the month-end
5) Use your language’s equivalent to DataAdd to get your month-end date.
HTH
IBlearning
20 pts. | May 13 2005 9:24PM GMT
It is ILE RPG. The returned date should be able to handle any date entered by user.
A good example would be if the user entered 20050513 (today’s date), it would then return 20050630. Thank you again for your great knowledge and support.
matobey
0 pts. | May 16 2005 9:30AM GMT
In ILE RPG use the date BIF’s provided.
WrkDate and DateField are both defined as Date(D) data types.
1. Determine the first of the current month.
WrkDate = DateField - %Days(%SubDt(DateField:*days) - 1)
2. Add two months, then subtact 1 day (the order is important), this will give you the end of the next month.
WrkDate = WrkDate + %Months(2) - %Days(1)
you can combine this into one expression if you like.
By using the IBM functions you will not need to worry about leap year because the system will handle it.
Mike
MichelleDavidson
110 pts. | May 16 2005 10:03AM GMT
And Gail wrote in with this code. Just change the date format to suit your needs, she says.
– Michelle Davidson, editor, <a href="http://Search400.com" title="http://Search400. " target="_blank">Search400.com</a>
———————————————————————————————————————————————
* Determine Last Day of Month
D DateIn S D DATFMT(*MDY)
D DS
D DateEnd D DATFMT(*ISO)
D DateDay 2 OVERLAY(DateEnd:9)
C*
* Pass in Date Parameter (format is mmddyy)
C*
C *ENTRY PLIST
C PARM BDX 6
C*
* Calculate Number of Days in Month
C*
C MOVE BDX DATE6 6 0
C *MDY MOVE DATE6 DateIn
*
C DateIn ADDDUR 1:*M DateEnd
C EVAL DateDay = ‘01′
* DateEnd = End of Current Month
C SUBDUR 1:*D DateEnd
* DateEnd = End of Next Month
C ADDDUR 1*M DateEnd
MichelleDavidson
110 pts. | May 16 2005 12:18PM GMT
Tony Cole also sent in a suggestion and code.
– Michelle Davidson, editor, <a href="http://Search400.com" title="http://Search400. " target="_blank">Search400.com</a>
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
DTESTDATE S D
D WRKDATE S 6
D DOM S 2 0
CL0N01Factor1++++++++++Opcode&ExtFactor2++++++++++++++Result++++++++Len++D+HiLoEq
C *MDY0 MOVE WRKDATE TESTDATE
C EXTRCT TESTDATE:*D DOM
C EVAL DOM = (DOM - 1)
C SUBDUR DOM:*DAYS TESTDATE
C ADDDUR 2:*MONTHS TESTDATE
C SUBDUR 1:*DAYS TESTDATE
WRKDATE will be the date the user will enter in and should be a valid date in MMDDYY format.
EX. WRKDATE = 102504 (MMDDYY)
Move WRKDATE into date field TESTDATE. EX. TESTDATE = 102504 (MMDDYY)
EXTRCT - will put the days of the month into DOM. EX. DOM = 25
Subtract one day from DOM. EX. DOM = 24
SUBDUR - subtracts the number of days from TESTDATE. This will give you the first of the month.
EX. TESTDATE = 100104 (MMDDYY)
ADDDUR - will add 2 months to testdate. Now you have the first of the month two months ahead.
EX. TESTDATE = 120104 (MMDDYY)
SUBDUR - will sub 1 day from TESTDATE and you now have the the last day of the month.
EX TESTDATE = 113004 (MMDDYY)
So now TESTDATE will have Nov. 30 2004, which is the end of the month.
Since TESTDATE is a date field and using SUBDUR, ADDDUR this will handle leap years
MichelleDavidson
110 pts. | May 16 2005 12:27PM GMT
The code that I’ve posted on behalf of people is not posting correctly. If you would like the original code, please send me an email at <a href="mailto:editor@search400.com" title="mailto:editor@search400.com">editor at search400.com</a>. Sorry for the inconvenience.
Michelle Davidson
Editor
<a href="http://Search400.com" title="http://Search400.
" target="_blank">Search400.com</a>
MichelleDavidson
110 pts. | May 18 2005 10:49AM GMT
To make it easier to view the code users sent in, I’ve posted the samples in a separate document on <a href="http://Search400.com" title="http://Search400. " target="_blank">Search400.com</a> – <a href="http://www.search400.com/tip/1,289483,sid3_gci1089668,00.html" title="http://www.search400.com/tip/1,289483,sid3_gci1089668,00.html" target="_blank">http://www.search400.com/tip/1,289483,si…</a>
– Michelle Davidson, editor, <a href="http://Search400.com" title="http://Search400. " target="_blank">Search400.com</a>
TomLiotta
7990 pts. | Oct 28 2009 9:35PM GMT
Review this in STRSQL:
select
date((varchar(year(date(’2009-10-30′) + 2 months)) concat
‘-’ concat
right(’0′ concat
varchar(month(date(’2009-10-30′) + 2 months)),2)
concat ‘-01′)
) - 1 day
from sysibm/sysdummy1
Or this variation:
select
date((varchar(year( current date + 2 months)) concat
‘-’ concat
right(’0′ concat
varchar(month( current date + 2 months)),2)
concat ‘-01′)
) - 1 day
from sysibm/sysdummy1
The code can also be adapted to the VALUES … INTO format. The first form can be used in embedded SQL in all languages if the SQL Dev Kit is installed. It can be used in a REXX proc even if the SQL Dev Kit is not installed. In current releases, the VALUES … INTO form should also work in REXX, but there seems to be a bug that IBM is working on and hasn’t resolved yet — it doesn’t work properly at V5R4 on a test system.
Tom
TomLiotta
7990 pts. | Nov 26 2009 9:23AM GMT
re “REXX and VALUES INTO”…
IBM has so far decided that the REXX manuals will be changed to remove VALUES INTO from the list of supported statements rather than fix REXX. So much for the supported ‘cross-platform’ solution from IBM.
Tom






