Focal Point
[SOLVED] Finding the week number for any given year.

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

December 04, 2008, 04:18 PM
Denny99
[SOLVED] Finding the week number for any given year.
I have many transactions with a date time value and I want to determine within what week of the year that date time value falls. For example there are 52 weeks in a year and week 1 is 1/1/08 to 1/7/08 and week 2 is 1/8/08 to 1/14/08 and week 52 is 12/25/08 to 12/31/08 etc... I will then graph the results for the year; thus, I will have 52 plots on a graph which represents all my data for the full year of transactions. thanks for your time!

This message has been edited. Last edited by: Kerry,
December 04, 2008, 04:23 PM
Spence
DEFINE FILE CAR
DATE1/A10 WITH COUNTRY= TODAY(DATE);
DATE2/HMDYYs = HINPUT(14, DATE1, 8, 'HMDYYs');
WEEK/I2 = HPART(DATE2, 'WEEK', 'I2');
END
-*
TABLE FILE CAR
SUM
MAX.DATE1
MAX.DATE2
MAX.WEEK
END


WF 8 version 8.2.04. Windows.
In focus since 1990.
December 04, 2008, 05:04 PM
Francis Mariani
Unfortunately, this does not give the week number that Denny99 is looking for. The WEEK component of the Date-Time column is a Saturday-Friday week number (the range of which you can modify using the WEEKFIRST setting), while Denny99 is looking for a week number starting on the first day of the year, which may not be a Monday so there might be a discrepancy between the two.

2009:
 m  t  w  t  f  s  s  |  m  t  w  t  f  s  s
-- -- -- -- -- -- --  | -- -- -- -- -- -- --
          1  2  3  4  |  5  6  7  8  9 10 11
          0  0  1  1  |  1  1  1  1  1  2  2 <== week component of date-time field
          1  1  1  1  |  1  1  1  2  2  2  2 <== week number

I think you have to do this using the day-of-year component and divide by 7.

DEFINE FILE CAR
DATE1/A8 WITH COUNTRY= '20080108';
DATE2/HMDYYS = HINPUT(14, DATE1, 8, 'HMDYYS');
WEEK/I2 = HPART(DATE2, 'WEEK', 'I2');
DOY/I3 = HPART(DATE2, 'DAY-OF-YEAR', 'I3');
WEEKB/I2 = IF IMOD(DOY, 7, 'I3') EQ 0 THEN (DOY / 7) ELSE (DOY / 7) + 1;
END

TABLE FILE CAR
SUM
MAX.DATE1
MAX.DATE2
MAX.WEEK
MAX.DOY
MAX.WEEKB
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 04, 2008, 06:09 PM
Darin Lee
Probably doesn't matter much, but the last day of the year is going to give you a 53rd plot point because a year is 52 weeks and 1 (or 2) days. Francis' code, for most purposes, solves the problem as it uses modular division but that still doesn't resolve the issue of the extra day(s).


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
December 04, 2008, 09:00 PM
Waz
As the length of a year is virtually constant, give or take 1 second from year to year, the calc of weeks 1 to 52/53 is the best way.

All depends on what Denny99 wants in his graph.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

December 05, 2008, 02:04 AM
Tony A
... and don't forget that there are differences between week numbers depending upon what standard you need to use - MS or ISO 8601.

ISO 8601 begins numbering weeks for the first week to contain a Thursday (other factors as well but this is the main one) whereas MS (as usual) decide that week number one is the first whole week within a year.

Find out which convention that you are required to use and code accordingly.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
December 05, 2008, 09:13 AM
FrankDutch
Thinking of week numbers and things like that I would recommend this article.

The French Revolutionairy Calendar

It's a funny idea ....




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

December 05, 2008, 01:11 PM
susannah
Sansculottides
Big Grin LOL
what a leap year tradition!
except the french seem to have it for 5 days instead of 1
say,,summit is about 5 days long...
hmmmm




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
December 05, 2008, 01:41 PM
FrankDutch
Yes

I tell my boss I go to Summit this afternoon and I will be back tomorrow......




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