Focal Point
[SOLVED] Working with date ranges based on Period

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/60110967

April 09, 2009, 05:44 PM
Rafa
[SOLVED] Working with date ranges based on Period
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?

Example:
YEAR:2009
MONTH:2
I need to have:
STARTDATE=? (1/1/2009)
ENDDATE=? (1/28/2009)

Thanks,

Rafael Rangel

This message has been edited. Last edited by: Kerry,


Rafa
April 10, 2009, 08:14 AM
Kofi
Rafael,

I think use DATEMOV yes? Have month year add 1 for month/1/year as BOM then DATEMOV EOM? Simple No?

Kofi


Client Server 8.1.05: Apache; Tomcat;Windows Server 2012
Reporting Server 8.1.05; Oracle; MS SQL; Windows Server 2012
April 10, 2009, 10:37 AM
susannah
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.




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
April 10, 2009, 11:42 AM
GamP
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...


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
April 10, 2009, 02:46 PM
FrankDutch
and to learn more on date manipulation you might be interested in buying the book
"almost 1001 ways to work with dates...."




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

April 15, 2009, 05:37 PM
Rafa
I am still having problems with this.I did the following as per Susannah's suggestion:

quote:
-DEFAULT &RPTYEAR='2009'
-DEFAULT &RPTMONTH='03'

-SET &STARTDATE = &RPTYEAR | &RPTMONTH | '01';
-SET &ENDDATE = DATEMOV (&STARTDATE, 'EOM');


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.

Any ideas?

Thanks,

Rafael


Rafa
April 15, 2009, 05:47 PM
GinnyJakes
Check out Francis' reply (2nd from last) in this post:
http://forums.informationbuild...941036171#5941036171

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.


Ginny
---------------------------------
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
April 16, 2009, 09:08 AM
linus
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 ;




WF 7.7.05
HP-UX - Reporting Server, Windows 2008 - Client, MSSQL 2008, FOCUS Databases, Flat Files
HTML, Excel, PDF
April 16, 2009, 09:39 AM
PBrightwell
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
 



Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
April 16, 2009, 04:38 PM
Rafa
I ended up going for PBrightwell's solution. It works like a charm.

Thank you everybody for your help.

Rafael

BTW - I ordered the 1001 ways to work with dates book. This seemingly simple stuff was driving me crazy.