Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATES SUBTRACTION

Status
Not open for further replies.

ozi2

Programmer
Sep 1, 2002
40
0
0
IL
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
 
Hi Oz,

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
 
First, a question or two:
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.
 
HI,

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
 
1. Regular procedure is fine.
2. Post your code. Let's take a look at it and then maybe we can make suggestions.
 
Without knowing what you've coded, it's tough to determine why it failed. The code provide by Tewy SHOULD work. I coded it on a 4.3.1 release, as follows:
[tt]
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
[/tt]
and got the following:
[tt]
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
[/tt]
which appears to be correct. Perhaps you're not putting the dates into a 'smart' date format?
 
Hi;

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
 
OK, then you probably want to do the calculation in the Dialogue Manager. Let me first assume you can get each of the dates into a YYMD format. If so, then you can use the subroutine YM, which calculate the number of months between to numeric dates in [Y]YM format (2 or 4 digit years). Here's an example:

[tt]
-SET &FROMDATE = 20021012;
-SET &TODATE = 20030126;
-SET &FROMYM = &FROMDATE/100;
-SET &TOYM = &TODATE/100;
-SET &MONTHS = YM(&FROMYM,&TOYM,'I4');
[/tt]
 
Hi,

10'x, it works great.
How do I know to which number to divide?

ZO

 
The first two -SET statements assign integer values in YYMD format to the variables.
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.
 
You're dividing by 100, because the date is a number in the format [YY]YYMMDD. Dividing by 100 removes the day portion (the last 2 positions), leaving just the year-month part. The YM routine expects dates as numbers in the format [YY]YYMM (just year and month).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top