×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

DATES SUBTRACTION

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

RE: DATES SUBTRACTION

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

RE: DATES SUBTRACTION

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.   

RE: DATES SUBTRACTION

(OP)
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

RE: DATES SUBTRACTION

1. Regular procedure is fine.
2. Post your code. Let's take a look at it and then maybe we can make suggestions.

RE: DATES SUBTRACTION

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:

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

(OP)
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

RE: DATES SUBTRACTION

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:


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

RE: DATES SUBTRACTION

(OP)
Hi,

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

ZO

RE: DATES SUBTRACTION

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.

RE: DATES SUBTRACTION

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).

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close