DATES SUBTRACTION
DATES SUBTRACTION
(OP)
Hi,
I want to subtract from the curent date a customized date
I get from an html form. The html format of the date is MM/DD/YYYY,
for example Aug 10 2003 will be displayed as 08/10/2003.
I want to subtract from current date (I use TODAY function)
my date in order to get the nomthes between them. (YM function).
Any idea will be appreciated.
OZ
I want to subtract from the curent date a customized date
I get from an html form. The html format of the date is MM/DD/YYYY,
for example Aug 10 2003 will be displayed as 08/10/2003.
I want to subtract from current date (I use TODAY function)
my date in order to get the nomthes between them. (YM function).
Any idea will be appreciated.
OZ
RE: DATES SUBTRACTION
There are many ways of doing this, I would use the &YYMD function to return the current date, a define for what you want would then look like this:
DATE1/YYMD=&YYMD;
DATE2/MDYY='11022002';
DIFF/I4=DATEDIF(DATE2, DATE1, 'M');
where DATE2 is the date returned from your HTML form. This would be easier than using the TODAY function which returns the date as an Alpha field with embedded slashes.
regards,
Tewy
RE: DATES SUBTRACTION
1. What release of FOCUS are you using?
2. What operating system?
Second:
Given the YM function's use of the YM form of the date, you have to extract the Y and M portions of the the HTML date, convert them to numeric, and then concatentate them.
The EDIT function will do the extraction nicely.
If the HTML is date is in MM/DD/YYYY form, then
in a DEFINE or COMPUTE
HTML_YYYY/I04L = EDIT (HTML_DATE,'$$$$$$9999');
This selects the seventh through the tenth characters of the field and assigns them to an integer field four bytes wide.
HTML_MM/I02L = EDIT (HTML_DATE,'99');
Similarly this will select the first two charcaters of the field.
HTML_YYMM/I06 = HTML_YYYY | HTML_MM;
This will concatenate the year and the month in a form to be used with YM function.
You can handle the current date similarly.
Test the output of the YM function: if it returns 0, there are two possible causes. The two arguments passed to it are numerically identical or one of the arguments is not valid.
HTH.
RE: DATES SUBTRACTION
I'm using WebFOCUS 4.31 om Win. 2K.
I tried both solutions and none of them worked.
When I watch the source I see WebFocus message "UNRECOGNIZED COMMAND..".
I used the code in a regular procedure (not a maintain proc.).
If I need to use it in a maintain one, can you please give me more details
how to do this and how to connect between the maintain file and
the .fex file.
Thanks a lot,
OZ
RE: DATES SUBTRACTION
2. Post your code. Let's take a look at it and then maybe we can make suggestions.
RE: DATES SUBTRACTION
DEFINE FILE CAR
DATE1/YYMD=&YYMD;
DATE2/MDYY='11022002';
DIFF/I4=DATEDIF(DATE2, DATE1, 'M');
END
TABLE FILE CAR
PRINT DATE1 DATE2 DIFF BY COUNTRY
END
and got the following:
COUNTRY DATE1 DATE2 DIFF
------- ----- ----- ----
ENGLAND 2003/08/12 11/02/2002 9
FRANCE 2003/08/12 11/02/2002 9
ITALY 2003/08/12 11/02/2002 9
JAPAN 2003/08/12 11/02/2002 9
W GERMANY 2003/08/12 11/02/2002 9
which appears to be correct. Perhaps you're not putting the dates into a 'smart' date format?
RE: DATES SUBTRACTION
Sorry I didn't explain it well:
I don't need to compute the date in TABLE OR DEFINE COMMAND.
I just need to calculate the monthed netween two dates:
current date and a date I get from the user.
According to the result I'll know where to go in my file
or which remark to write to the user.
Thank's again,
OZ
RE: DATES SUBTRACTION
-SET &FROMDATE = 20021012;
-SET &TODATE = 20030126;
-SET &FROMYM = &FROMDATE/100;
-SET &TOYM = &TODATE/100;
-SET &MONTHS = YM(&FROMYM,&TOYM,'I4');
RE: DATES SUBTRACTION
10'x, it works great.
How do I know to which number to divide?
ZO
RE: DATES SUBTRACTION
The second two -SET statements essentially remove the D, or day, portion of the date by moving the (implied) decimal point two positions to the left. Given the integer format, only the whole portion of the number is assigned to the variables.
RE: DATES SUBTRACTION