Focal Point
calculate number of weeks between two yyyymmdd dates
December 01, 2008, 02:20 AM
Pro4GLcalculate number of weeks between two yyyymmdd dates
Does anyone has codes to calculate number of weeks between two yyyymmdd dates ?
week define as Monday to Sunday, if begin date is not Monday then 1st week is partial and all the other weeks are from Monday to Sunday until the last week equal to ending date and it can be partial too.
WF 8202, windows
December 01, 2008, 04:11 AM
FrankDutchDear Pro
If you compute the two dates as a number since the beginning of the year and divide that number by 7 and as integer you have two weeknumbers.
the difference is your result.
|
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 01, 2008, 04:55 AM
FransHi Pro4GL,
What do you want to see when startdate is in week 4 on friday and enddate is in week 5 on tuesday? Should this be 1 week since it's a different week, or 0 week because there are less then 7 days in between?
Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
December 01, 2008, 10:32 AM
Francis MarianiYou could use the Date/Time function HDIFF "Find the Number of Units Between Two Date-Time Values" which allows for a Week component (it even allows you set the first day of the week using the WEEKFIRST parameter - SET WEEKFIRST = 7). You simply have to convert the Date columns to Date/Time columns using the Date/Time function HDTTM "Convert a Date Value to a Date-Time Value". Check out the WebFOCUS Functions manual.
DEFINE FILE CAR
DT1/YYMD = '20080910';
DT2/YYMD = '20081025';
-*-- Convert Date to Date/Time
DTTM1/HYYMDS = HDTTM(DT1, 8, 'HYYMDS');
DTTM2/HYYMDS = HDTTM(DT2, 8, 'HYYMDS');
DIFF1/D6 = HDIFF(DTTM2, DTTM1, 'WEEK', 'D6');
END
TABLE FILE CAR
PRINT
COUNTRY
DT1 DT2
DTTM1 DTTM2
DIFF1
WHERE READLIMIT 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 01, 2008, 12:07 PM
BailleclGet for both Starting Date and Stopping Date
1) the number of times 7 is "included in"
2) the remainder of this division
(YYMMDD is a number of Days since something around 31/12/1900, but you probably know better than I ..)
The remainder of the division gives the Day in the week : Monday is 0 and Sunday 6.
With this information Stachanov can solve your problem.
Some One-Liners will give you more concise solutions.
But it's the idea and Focus doesn't any longer need Masking Dates or INUMBEROFDAYS because the Date Format is great ( and Popular ?)
Cordialement
Focus Mainframe 7.6.11
Dev Studio 7.6.11 and !!!
PC Focus, Focus for OS/2, FFW Six, MSO
December 01, 2008, 12:14 PM
BailleclMy Godness, I've turned Sylver member !!!
Rather think of a growing old Don Quichotte, with a rusty armour. (and still with the head in the stars, notwithstanding the fact that his feet are in the mud ...)
Focusely and Cordialy
Focus Mainframe 7.6.11
Dev Studio 7.6.11 and !!!
PC Focus, Focus for OS/2, FFW Six, MSO
December 01, 2008, 01:42 PM
<JG>quote:
PC Focus, Focus for OS/2, FFW Six
I hope you’ve cancelled the maintenance.
December 01, 2008, 01:50 PM
Francis MarianiAnd I thought a non-production version of WF 5.3.2 was bad!
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 02, 2008, 06:41 AM
arvindhi PRO4GL ,
We use a T_DB2_ACCT_DATE table . It is universal and can be used in any server. In that table we have a field called WK_I ( week ID) , using this column we can easily calculate the no. of weeks between any two dates.
you can ask ur admin to set up this table for you. This comes in handy and is very useful.
regards
Aravindan
WebFOCUS 714
Windows XP
Output: HTML,PDF,Excel
December 02, 2008, 08:52 AM
BailleclI, also, had the opportunity to sing 'Time is on my side' along with Mick Jagger (Which Version Mick Jagger ?)
But I know that my children or the children of my children will pass over your declining cleverness ...
Focusely
I thank you for the maintenance advice, I'll do that right now, along with bringing back my Minitel to the Post Office.
Focus Mainframe 7.6.11
Dev Studio 7.6.11 and !!!
PC Focus, Focus for OS/2, FFW Six, MSO
December 02, 2008, 09:20 AM
Francis MarianiYou must keep that Minitel, as a portal into the old world.
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