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 RangelThis 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:
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.