[CLOSED] Finding month number from given week and year number
Hello,
I came across a problem where I need to find the month number given a week and year number. Is there any function that can help me with this or will I have to burn a few more brain cells implementing some crazy algorythm?
Thanks in advance.This message has been edited. Last edited by: Kerry,
WebFOCUS App Studio 8103 Windows7 All outputs
December 13, 2011, 09:51 AM
Prarie
Please give an example of what you are looking for. Not quite sure what you are asking.
December 13, 2011, 11:44 AM
GamP
Maybe this is something that could help you with your algorithm:
DEFINE FILE CAR
WEEK/I4 WITH COUNTRY = 12;
YEAR/YY WITH COUNTRY = 2004;
FDAY/DMYY = YEAR;
FWEEK/I2 = EDIT(EDIT(HYYWD(HDTTM(FDAY,8,'HYYMDIA'),'A10'),'$$$$$$99'));
FWEEK = IF FWEEK GT 1 THEN 0 ELSE 1;
DAYS = (WEEK - FWEEK) * 7;
HELP/DMYY = FDAY + DAYS;
NEWDATE/MYY = HELP;
END
TABLE FILE CAR
PRINT WEEK YEAR NEWDATE
END
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
December 13, 2011, 04:33 PM
Dan Satchell
Similar to GamP's solution, but using different functions. First day of the year (JAN01) is converted to the number of days since WF base date (12/31/1900). Number of weeks is multiplied by 7 to obtain number of days. This number is added to the JAN01 base days (minus 1 because we start with the first day of the year). Finally, the total base days are converted back to a month SmartDate and then to a month number. Replace &DATEYY with your year and WEEK_NUMBER with your week number.
APP PREPENDPATH IBISAMP
-*
DEFINE FILE CAR
JAN01/A8YYMD WITH COUNTRY = '&DATEYY' | '0101';
WEEK_NUMBER/I2 WITH COUNTRY = 11 ;
YEAR_NUMBER/I6 = DATECVT(JAN01,'A8YYMD','I6');
DAY_NUMBER/I3L = (WEEK_NUMBER * 7) - 1 ;
YEAR_DAY/I6 = YEAR_NUMBER + DAY_NUMBER ;
YEAR_MONTH/M = DATECVT(YEAR_DAY,'I6','M');
MONTH_NUMBER/I2 = YEAR_MONTH ;
END
-*
TABLE FILE CAR
PRINT
YEAR_NUMBER
DAY_NUMBER
YEAR_DAY
YEAR_MONTH
MONTH_NUMBER
WHERE RECORDLIMIT EQ 1 ;
END
This message has been edited. Last edited by: Dan Satchell,
WebFOCUS 7.7.05
December 13, 2011, 04:46 PM
Francis Mariani
Here's another method to determining the month:
-* File date_from_week.fex
DEFINE FILE CAR
DT_YEAR/I4 = 2009;
DT_WEEK/I2 = 24;
DT_1/A8YYMD = EDIT(DT_YEAR) || '0101';
DT_1H/HYYMD = HINPUT(8, DT_1, 8, 'HYYMDS');
DT_2H/HYYMD = HSETPT(DT_1H, 'WEEK', DT_WEEK, 8, DT_2H);
DT_MONTH/I2 = HPART(DT_2H, 'MONTH', DT_MONTH);
END
TABLE FILE CAR
PRINT
COUNTRY
DT_YEAR
DT_WEEK
DT_1H
DT_2H
DT_MONTH
WHERE RECORDLIMIT EQ 1
END
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
December 13, 2011, 06:04 PM
Dan Satchell
quote:
HSETPT
I haven't used HSETPT before. Nice.
WebFOCUS 7.7.05
December 13, 2011, 08:57 PM
Francis Mariani
Gotta use these crazy functions somewhere
It'll be fun to see how many solutions are suggested before diogopc responds.
Francis
Give me code, or give me retirement. In FOCUS since 1991
Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server