Is valid to use variable dates in the DATEDIF function?
how I could I get the number of days of the lapse of time that my users select in the report?
Thanks for your help!
greetings! TonyThis message has been edited. Last edited by: Kerry,
WebFocus 7.6.10, windows 7, win server 2003-2008 PDF, TXT, XML, html, xls, doc
May 20, 2011, 04:56 AM
websmash
Hi just try to add quotes to the vars COMPUTE Numdias1/I3 = DATEDIF('&ENTREGAFECHA', '&ENTREGAFECHA2', 'D');
greetings Andy
May 20, 2011, 09:49 AM
Emily Max
Hi Tony, Dates in WebFocus can be a little tricky. You have to use an I8 format for date function. So you will first need to convert your &variable dates and then use the datedif function. If your users use a mm/dd/yyyy format, the following code will work.
and now alter the output format to an hold file and see what the echo shows you?
The suggestion of Emily could also help you to show what the user did type in for the begin en enddate amper values.
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
May 21, 2011, 08:33 AM
George Patton
There appears to be a small typo here:
quote:
WHERE ( REPARTOCIRCULACION.ENTREGAFECHA GE '&ENTREGAFECHA' ) AND ( REPARTOCIRCULACION..ENTREGAFECHA LE '&ENTREGAFECHA2' );
- two periods between the SEGNAME and FIELDNAME -
I assume because you are still testing that you are entering the dates in a consistent format, but as Emily points out you may have to strip out unwanted characters and re-arrange if you allow users to type in the dates. The only useful date format is YYMD (which happens to be the SI standard, so why the heck do people still write MM/DD/YY ! ... grrrrr). When you get into production I would strongly suggest you only allow your users to use the calendar picker, so the dates automatically get returned as YYMD format and the users can't 'muck' up by putting in dates wrong.
Originally my field looks like this: DMYY (across Latin America use this format.) I Change the format as suggested by a DEFINE: entregafecha / YYMD = REPARTOCIRCULACION. ENTREGAFECHA; Subsequently use the following question:
WHERE (REPARTOCIRCULACION.entregafecha GE '& entregafecha') AND (REPARTOCIRCULACION.entregafecha LE '& entregafecha2'); I put a calendar control for my users to choose the date
entregafecha = 2011/05/05 and entregafecha2 = 2011/05/09
and the result in Numdias is equal to "-36"This message has been edited. Last edited by: anrix,
WebFocus 7.6.10, windows 7, win server 2003-2008 PDF, TXT, XML, html, xls, doc
May 30, 2011, 03:22 AM
FrankDutch
this should work
-SET &ECHO=ALL;
-PROMPT &STARTDATE_DDMMYYYY.Give the startdate.
-PROMPT &ENDDATE_DDMMYYYY.Give the end date.
-DEFAULT &STARTDATE_DDMMYYYY=11052011;
-DEFAULT &ENDDATE_DDMMYYYY=19052011;
-SET &DAY1=EDIT(&STARTDATE_DDMMYYYY,'99$$$$$$');
-SET &MAAND1=EDIT(&STARTDATE_DDMMYYYY,'$$99$$$$');
-SET &YEAR1=EDIT(&STARTDATE_DDMMYYYY,'$$$$9999');
-SET &STARTDATE=&YEAR1||&MAAND1||&DAY1;
-TYPE &STARTDATE
-SET &DAY2=EDIT(&ENDDATE_DDMMYYYY,'99$$$$$$');
-SET &MAAND2=EDIT(&ENDDATE_DDMMYYYY,'$$99$$$$');
-SET &YEAR2=EDIT(&ENDDATE_DDMMYYYY,'$$$$9999');
-SET &ENDDATE=&YEAR2||&MAAND2||&DAY2;
-TYPE &ENDDATE
DEFINE FILE CAR
NUMDAYS/I10 WITH CAR = DATEDIF('&STARTDATE','&ENDDATE','D');
END
TABLE FILE CAR
PRINT NUMDAYS
END
It is not the most elegant way, but I used it many years ago when we did not have so much functions to translate.
It does not handle any typing errors
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
May 30, 2011, 10:18 AM
GamP
quote:
and the result in Numdias is equal to "-36"
As websmash already said in his first reply to this, you have to add quotes around the variables. If you don't you'll get -36 as a result, if you do, you get 4.
GamP
- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
May 30, 2011, 10:55 AM
anrix
Perfect!
is working properly!
thank you very much to all who answered!
Greetings from Mexico!
Tony
WebFocus 7.6.10, windows 7, win server 2003-2008 PDF, TXT, XML, html, xls, doc