Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]difference between 2 dates in WEEKS!

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED]difference between 2 dates in WEEKS!
 Login/Join
 
Platinum Member
posted
How would you find the difference between 2 dates and put it in weeks, Both the dates are coming in as parameters!

Ex.

&SDATE MDYY ____3/1/2011
&EDATE MDYY ____3/15/2011

OUTPUT = I5_____2

This message has been edited. Last edited by: Charles Richards,


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
In Dialog Manager, or in Reporting Language (Define)?

How do you want to handle cases where the difference is not an exact multiple of seven days?
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Platinum Member
posted Hide Post
i would just like it to be rounded to the nearest integer, and a define would work!

ex
3/7 =0
4/7 =1


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
subtracting dates can be done in many ways but as j.gross asked it depends if it are database fields or DM values.

please try to get the book "1001 ...." it helps a lot in date issues.

the rounding issue was posted by me with a function you can use.




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

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Report This Post
Expert
posted Hide Post
I would use the DATEDIF function to determine the number of days between the two dates, then divide by 7 to determine the number of weeks.


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
Or you could use legacy date function DAMDY. However, this approach assumes the input dates are always in the format 'mm/dd/yyyy', including leading zeroes.

-SET &SDATE = '03/05/2011';
-SET &EDATE = '03/15/2011';
-SET &SDATEX = EDIT(&SDATE,'99$99$9999');
-SET &EDATEX = EDIT(&EDATE,'99$99$9999');
-SET &WEEK_DIFF = (DAMDY(&EDATEX,'I8') - DAMDY(&SDATEX,'I8')) / 7 ;
-TYPE &WEEK_DIFF


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Platinum Member
posted Hide Post
WKS/D12.2=DATEDIF(DAMDY(&SDATE, 'I8'), DAMDY(&EDATE, 'I8'), 'D');

I used the above line in my define and it doesn't seem to work, I can't seem to get this define working, is there an alturnative way, like calculating it with a compute?

INPUT

&SDATE
&EDATE


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Expert
posted Hide Post
quote:
it doesn't seem to work, I can't seem to get this define working

When this occurs, it's helpful to tell us what error or incorrect result you got.


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Platinum Member
posted Hide Post
it calculates it to be either a 0 or .00, when i should be getting a 1.

&SDATE = 4/30/2011
&EDATE = 5/6/2011


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
Isn't that because the difference between those dates is 6?
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Report This Post
Virtuoso
posted Hide Post
If you want a DEFINE/COMPUTE, try something like this:

-SET &SDATE = '4/30/2011';
-SET &EDATE = '5/6/2011';
-*
DEFINE FILE CAR
 SDATE/MDYY WITH COUNTRY = '&SDATE';
 EDATE/MDYY WITH COUNTRY = '&EDATE';
 WEEK_DIFF/F3 = (DATEDIF(SDATE,EDATE,'D')) / 7 ;
END
-*
TABLE FILE CAR
 PRINT SDATE EDATE WEEK_DIFF
 WHERE RECORDLIMIT EQ 1 ;
END

This message has been edited. Last edited by: Dan Satchell,


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Platinum Member
posted Hide Post
SDATE/MDYY WITH COUNTRY = '&SDATE';



what does the "WITH COUNTRY" mean?

This message has been edited. Last edited by: Charles Richards,


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
Remove it and find out. In multi-segment files (like the CAR file) DEFINEs must reference a real field, a previously defined field, or must have an explicit field reference (e.g., 'WITH COUNTRY'). Otherwise FOCUS does not know to which segment it should attach the DEFINEd field.

This message has been edited. Last edited by: Dan Satchell,


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Platinum Member
posted Hide Post
I can't figure out what i seem to be doing wrong...

I am running the fex file and added the define variable WKS int the header as
latest attempt:

SDATE/I8MDYY = DATECVT(&SDATE,'I8MDYY','MDYY');
EDATE/I8MDYY = DATECVT(&EDATE,'I8MDYY','MDYY');
WKS/D8 = (DATEDIF(SDATE,EDATE,'D')) / 7 ;

also tried

SDATE/I8MDYY = '&SDATE';
SDATE/I8MDYY = '&EDATE';
WKS/D8 = (DATEDIF(SDATE,EDATE,'D')) / 7 ;

HINT** the dates will be coming from a calender box from the HTML Composer

This message has been edited. Last edited by: Charles Richards,


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
SDATE/MDYY = '&SDATE';
EDATE/MDYY = '&EDATE';
WKS/D8 = (DATEDIF(SDATE,EDATE,'D')) / 7 ;


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Platinum Member
posted Hide Post
Im still recieveing a 0 as the output, i even took the " / 7 " (divid by seven) out just to see if i get the difference in days and still a 0. I put the varible SDATE and EDATE in the header just to see what is getting put in them and the dates look exactly how they are suppose to, I don't know what I am doing wrong...

UPDATE: it seems to be working, but the output is 5,727

for
SDATE 04/30/2011
EDATE 05/06/2011

This message has been edited. Last edited by: Charles Richards,


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
I believe 5,727 is the number of weeks between 1/1/1901 and 5/6/2011. So it appears your code is using 1/1/1901 for SDATE instead of 4/30/2011. This would indicate an error somewhere in the code that handles the incoming value for &SDATE. The value for SDATE is therefore defaulting to the FOCUS base date of 1/1/1901. Put the following statement at the top of your program so you can see what is happening in your code.

-SET &ECHO = ALL ;


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Platinum Member
posted Hide Post
ok I added that in, but it only works upon an error...

I added this to the header to see the values
"< WKS"
"< SDATE < EDATE"

and it is giving me

5,727
04/30/2011 05/06/2011

so It appears to be using the correct values


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Expert
posted Hide Post
Works in this test fex:

-SET &SDATE = '04/30/2011';
-SET &EDATE = '05/06/2011';

DEFINE FILE CAR
SDATE/MDYY = '&SDATE';
EDATE/MDYY = '&EDATE';
WKS/D8 = (DATEDIF(SDATE,EDATE,'D')) / 7 ;
END
-RUN

TABLE FILE CAR
PRINT 
SDATE
EDATE
WKS
BY COUNTRY
WHERE RECORDLIMIT EQ 1
END
-RUN


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Guru
posted Hide Post
Have you tried using the HDIFF function. It has a type of 'WEEK'?


WF 7.6.11
Oracle
WebSphere
Windows NT-5.2 x86 32bit
 
Posts: 398 | Registered: February 04, 2008Report This Post
Member
posted Hide Post
Hello charles you might want to check the date output from the date control, it gives you the option to automatically pass the date as yyyymmdd otherwise you have to convert the date from mm/dd/yyyy to yyyymmdd then use the datedif function.

-SET &ECHO = 'ALL';
-DEFAULT &SDATE = '20110228';
-DEFAULT &EDATE = '20110506';

TABLE FILE CAR
PRINT MODEL COUNTRY
COMPUTE DAYS/I8 = DATEDIF('&SDATE','&EDATE','D');
COMPUTE WKS/I8 = (DATEDIF('&SDATE','&EDATE','D'))/7;
END

try this


7610, Windows 64, Win 7
Excel, PDF, HTML
 
Posts: 5 | Registered: June 02, 2011Report This Post
Platinum Member
posted Hide Post
Just tried your suggestion of HDIFF


Code:
WKS/I5 = (HDIFF('&SDATE','&EDATE','WEEK','I5'));

Echo:
WKS/I5 = (HDIFF('04/30/2011','05/06/2011','WEEK','I5'));


I can run francis's code and it works fine, then when i copy and paste it into my fex it doesn't work... i put it at the top of the fex file

might it have something to do with
SET SUMMARYLINES = NEW
thats the only code in front of it

i even hardcoded the dates in there and it still would not give me the correct values!

Code:


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Platinum Member
posted Hide Post
quote:
-SET &SDATEX = EDIT(&SDATE,'99$99$9999');
-SET &EDATEX = EDIT(&EDATE,'99$99$9999');
-SET &WEEK_DIFF = (DAMDY(&EDATEX,'I8') - DAMDY(&SDATEX,'I8')) / 7 ;
-TYPE &WEEK_DIFF


ECHO:

-SET &SDATEX = EDIT(04/30/2011,'99$99$9999');
-SET &EDATEX = EDIT(05/06/2011,'99$99$9999');
-SET &WEEK_DIFF = (DAMDY(05062011,'I8') - DAMDY(04302011,'I8')) / 7 ;
-TYPE 0
0


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Expert
posted Hide Post
 
-SET &ECHO=ALL;
-SET &DATE1  = '04/30/2011';
-SET &DATE2  = '05/06/2011';
-SET &SDATEX = EDIT(&DATE1,'$$$$$$9999/') | EDIT(&DATE1,'99999');
-SET &EDATEX = EDIT(&DATE2,'$$$$$$9999/') | EDIT(&DATE2,'99999');
-SET &DIFF1  = (DATEDIF('&SDATEX.EVAL', '&EDATEX.EVAL', 'D') + 1) / 7;
-TYPE &DIFF1 
-EXIT


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Virtuoso
posted Hide Post
I sometimes forget about my WF environment settings. For the code below to work, DMPRECISION must be set to zero so Dialogue Manager will round up instead of truncating decimals. With DMPRECISION=0, both of these examples should work.

-SET &ECHO = ALL ;
SET DMPRECISION = 0
-RUN
-SET &SDATE = '04/30/2011';
-SET &EDATE = '05/06/2011';
-SET &SDATEX = EDIT(&SDATE,'99$99$9999');
-SET &EDATEX = EDIT(&EDATE,'99$99$9999');
-SET &WEEK_DIFF = (DAMDY(&EDATEX,'I8') - DAMDY(&SDATEX,'I8')) / 7 ;
-TYPE &WEEK_DIFF


-SET &ECHO = ALL ;
SET DMPRECISION = 0
-RUN
-SET &SDATEX = EDIT('04/30/2011','99$99$9999');
-SET &EDATEX = EDIT('05/06/2011','99$99$9999');
-SET &WEEK_DIFF = (DAMDY(&EDATEX,'I8') - DAMDY(&SDATEX,'I8')) / 7 ;
-TYPE &WEEK_DIFF


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Expert
posted Hide Post
Charles,

I feel we're flogging a dead horse here!

Do you need a solution for Dialogue Manager or for TABLE, or both?


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
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Platinum Member
posted Hide Post
Thanks for all the help. This code is what managed to work for me

SET DMPRECISION = 0
-RUN
-SET &SDATEX = EDIT(&SDATE,'$$$$$$9999/') | EDIT(&SDATE,'99999');
-SET &EDATEX = EDIT(&EDATE,'$$$$$$9999/') | EDIT(&EDATE,'99999');
-SET &DIFF1 = (DATEDIF('&SDATEX.EVAL', '&EDATEX.EVAL', 'D') + 1) / 7;
-TYPE &DIFF1


Last question is how Can i use the value "&DIFF1" in a compute or define?


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
DEFINE FILE XXXX

NUMBERWEEKS/I3=&DIFF1;
END

done




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

 
Posts: 2387 | Location: Amsterdam, the Netherlands | Registered: December 03, 2006Report This Post
Platinum Member
posted Hide Post
Thank you everyone for all of your help!!


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 111 | Registered: May 12, 2011Report This Post
Virtuoso
posted Hide Post
Yea!!
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]difference between 2 dates in WEEKS!

Copyright © 1996-2020 Information Builders