I am working on some accounting reports that take as parameters YEAR and MONTH for the data selection. But some of the tables I am working with use date fiels so I need to create a couple of variable that can have a start and end date for the where statement. Could someone help me with a function that might work so I can create those dates using as parameters the YEAR and MONTH?
I need to have:
Rafael RangelThis message has been edited. Last edited by: Kerry,
I think use DATEMOV yes? Have month year add 1 for month/1/year as BOM then DATEMOV EOM? Simple No?
Client Server 8.1.05: Apache; Tomcat;Windows Server 2012
Reporting Server 8.1.05; Oracle; MS SQL; Windows Server 2012
Is the parameter for MONTH being passed as 2 or 02?
If you can control the parameter list, its best to pass it as 02
then what field format is your date field in in your database, for the WHERE compare?
-SET &MYDATE = &MYYEAR | &MYMONTH | '01';
The DATEMOV function will then give you the last day of that given month, as , ahem, 'Kofi' says ; There are a couple of other ways to do that, as well.
But you have to know what your target format needs to be, to match your database field format.
Aha, you meant to say 2/1/2009 and 2/28/2009... or better: you want the first and last day of the month for a given month.
Kofi and Susannah are both right. Use DATMOV or any other method that suits your needs. There are many ways to get where you need to be...
and to learn more on date manipulation you might be interested in buying the book
"almost 1001 ways to work with dates...."
I am still having problems with this.I did the following as per Susannah's suggestion:
The query is taking ok the &STARTDATE, but &ENDDATE is not working as it fails and I get the following error:
THE FORMAT OF THE TEST VALUE IS INCONSISTENT WITH FIELD FORMAT:
I think this is happening because WF thinks &ENDDATE Iis a character string and not a date.
Check out Francis' reply (2nd from last) in this post:
This will do exactly what you want.
DATEMOV requires a smart date. Using functions with Dialogue Manager variables requires formats to be specified in the parameters for the function.
You might want to do some reading in the "Using Functions" manual.
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
This is the technique I use -- it's the "old" way of coding but it works great. In the below code I'm passing in a year (&DPYEAR) and a month (&DPERIOD). I use the IMOD() function on the year to determine if the value passed in for year is a leap year or not. I then check the value passed in for month and set my &var &EOM to the correct value. I then concatenate the three fields together -- this snippet of code is wrapped into a loop in my fex -- you can just remove the .&ctr to use it not in a loop. Hope this helps.
-SET &REMAINDER = IMOD(&DPYEAR, 4, 'I3L'); -SET &EOM.&CTR = IF (&DPERIOD.&CTR EQ '02') AND (&REMAINDER EQ 0) THEN '29' ELSE - IF (&DPERIOD.&CTR EQ '02') AND (&REMAINDER NE 0) THEN '28' ELSE - IF (&DPERIOD.&CTR EQ '01' OR '03' OR '05' OR '07' OR '08' OR '10' OR '12') THEN '31' ELSE '30'; -SET &EDPYMD.&CTR = &DPYEAR | &DPERIOD.&CTR | &EOM.&CTR ;
HP-UX - Reporting Server, Windows 2008 - Client, MSSQL 2008, FOCUS Databases, Flat Files
HTML, Excel, PDF
Another "old" way and you don't have to worry about leap year or days per month.
-SET &ECHO=ALL; -DEFAULT &RPTYEAR='2009' -DEFAULT &RPTMONTH='03' -SET &STARTYYM=&RPTYEAR | &RPTMONTH; -SET &NEXTMO=AYM(&STARTYYM, 1, 'I6YYM'); -SET &NEXTYYMD='&NEXTMO.EVAL'|'01'; -SET &STARTDATE = &RPTYEAR | &RPTMONTH | '01'; -SET &ENDDATE = AYMD (&NEXTYYMD,-1,'I8YYMD'); -TYPE &ENDDATE &STARTDATE
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
I ended up going for PBrightwell's solution. It works like a charm.
Thank you everybody for your help.
BTW - I ordered the 1001 ways to work with dates book. This seemingly simple stuff was driving me crazy.
|Powered by Social Strata|