Focal Point
Adding Number of Days to Dates

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5601009331

September 22, 2005, 02:24 PM
slfmr
Adding Number of Days to Dates
I have 2 A15 dates:

05/16/2005 ->Date 1

and

06/3/2005 ->Date 2

How can I add 25 days to Date 1 giving me a Date 3?

Then using Date 3 determine if Date 2 is less than Date 3.

I've looked up some info on subtracting dates, but nothing has jumped out at and, and since these are alpha I wasn't sure they would work the same way.

Can anyone help?

Thanks so much!
September 22, 2005, 03:22 PM
susannah
sure
look up the AYMD function.
you'll need to translate these character strings into smart dates, there are many ways to do that. one way uses the date convert function DATECVT. Smart dates being the focus word for integers underlying the date formatting map, integers representing the number of days elapsed since the base date of jan1 1900. Smart dates are the way to do all the arithmetic you need.
Look them both up in your FUNCTIONS manual
There are a number of threads on this board about DATES. So do a board search here as well.
You'll enjoy what you'll learn.
September 22, 2005, 03:53 PM
slfmr
Right, I had used datecvt, but I keep recieving errors and I am not sure why.

ND/DMY = DATECVT(DATE, 'MDYY', 'DMY');
ND/DMY = DATECVT(DATE, 'a255', 'DMY');

I have tried both of those...DATE is the name of the field that holds the date I need that is A255 but I want it to be in date format so that I can perform arithmetic.

The error tells me: (FOC36355) INVALID TYPE OF ARGUMENT #1 FOR USER FUNCTION DATECVT

But I need the first argument cause that is the date... not sure what to do.
I appreciate the AYMD hint (never seen that one), I assume I will use that once I figure this first part out.
September 22, 2005, 04:32 PM
Mickey
The WebFOCUS 53 "Using Functions" Document (DN4500583.0904) has the following explanation for using the DATECVT function.

DATECVT(date, 'infmt', 'outfmt'[, outfield])


WHERE
infmt
Alphanumeric
Is the format of the date enclosed in single quotation marks. It is one of the following:
* A non-legacy date format (for example, YYMD, YQ, M, DMY, JUL).
* A legacy date format (for example, I6YMD or A8MDYY).
* A non-date format (such as I8 or A6). A non-date format in infmt functions as an offset from the base date of a YYMD field (12/31/1900).


Going by that you should be able to use the following code to convert the date

DEFINE FILE CAR
-* Using A8MDYY Format
DATEA8/A8 WITH CAR = '01012005';
DTEONE/MDYY = DATECVT(DATEA8,'A8MDYY','MDYY');
-* USING A6 Format Approximately 100 years (365 * 100) from the base date of (12/31/1900)
DATEA6/A6 = '36500';
DTETWO/MDYY = DATECVT(DATEA6,'A6','MDYY');
END
TABLE FILE CAR
PRINT
DATEA8
DTEONE
DATEA6
DTETWO
END
Hope that helps
M

This message has been edited. Last edited by: <Maryellen>,
September 22, 2005, 07:19 PM
slfmr
Thanks for all the help. For some reason perhaps because I was pulling the date from an Oracle DB and it was an A255 I kept getting the same problem.

What I ended up doing was converting it in the SQL passthru that I used and then used HDATE to format it the way I needed.

Thanks!