[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference ilbbak::ibi_focus

Title:FOCUS, from INFORMATION BUILDERS
Moderator:ZAYIUS::BROUILLETTE
Created:Thu Feb 19 1987
Last Modified:Mon May 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:615
Total number of notes:1779

470.0. "Date arithmetic" by MISERY::BLUM_JO () Mon Oct 14 1991 20:34

    I know this is very simple, but I'm getting the syntax wrong or
    something.  How do you set a variable to the current date plus x
    number of days, using one of the date subroutines.  In other
    words if I wanted the variable to be today + 21, it should get the
    value of 11/4/91 (it doesn't have to be in this format, though).
    
    John
T.RTitleUserPersonal
Name
DateLines
470.1try AYMD subr.MLCADG::FERRARIFTue Oct 15 1991 06:3229
	Hi John, 

	you can use the subroutines 'AYMD'.
 
	AYMD (indate, days, outfield)

		indate: numeric - input date in format year-month-day.
		 	if date is not valid the subr, returns 0.

		days  : numeric - number of day to sum. use negative
			number to subtract days.

		outfield : integer - name of field containing the result 
			   date. 

	example:

	---> add 30 days to 'DATE'

	TABLE FILE yourfile
	PRINT FIELD1 DATE AND COMPUTE
	     AFTER30DAYS/I6YMD = AYMD (DATE, 30, AFTER30DAYS);
	BY NAME 
	END	

	Hope this help
	Fabio.
    
470.2AIMHI::CIONI_LTue Oct 15 1991 12:1822
With Version 5.2 and above of FOCUS, FOCUS supports a set of new date formats
designd to make date manipulation easier.

Included in this is the ability to simply add a number of days to a date field.

	PLUS_DATE/I6YMD = YOUR_DATE + 30;

	Other things included:

	Sorting dates regardless of display format
	Defining date components such as year and month or quarter and extract-
	ing them easily from the date fields.

	Doing arithmetic with dates and date comparisons without resorting to
	special date handling functions.

	Converting dates easily to other formats.

FYI.

LisaC
470.3Using -SETMISERY::BLUM_JOTue Oct 15 1991 15:309
    Thanks Fabio and Lisa.  What I'm really looking for is a way to
    -SET a variable as follows:
    
    -SET &BEGIN_DATE = &DATE +21;
    -SET &END_DATE   = &DATE +26;
    
    Any ideas on how to get this to work?
    
    John
470.4same subr.MLCADG::FERRARIFWed Oct 16 1991 06:219
	Try this:

-SET &&NEWDATE = 0;
-SET &&NEWDATE = AYMD (&OLDDATE, 30, 'I6');
-RUN
    
	Ciao
    	Fabio.
470.5related to .-1MLCADG::FERRARIFWed Oct 16 1991 06:2714
    
    	
    	P.S.
    	just to clarify,
    	
    	&olddate is your date in format YYMMDD
    	30       is number of days to add
    	'I6'     is the format of &&newdate (use quotation mark)
    
    	youdon't need to user && but can also be only &.
    
    	
        Regards
    	Fabio.
470.6AYMD subroutineMISERY::BLUM_JOWed Oct 16 1991 16:4117
    Thanks Fabio.
    
    I tried using the subroutine AYMD, but didn't have the apostrophies
    with the outfield (the documentation gives no indication apostrophies
    are required).  Also, I had to use the correct date variable (&YMD
    instead of &DATE).
    
    The field I'm screening for is the RVS_CMMT_DT in the Backlog database,
    which has a format of A6YMTD.  The correct -SET commands are:
    
    -SET &BEGIN_DATE = AYMD (&YMD, 21, 'I6YMD');
    -SET &END_DATE   = AYMD (&YMD, 26, 'I6YMD');
    
    
    Regards,
    
    John
470.8Substraction of days UTROP1::WOUW_FLove is a many sp(l)ended thingWed Oct 23 1991 07:3943
    Hi there,
    
    	As I'm trying to substract days from today's date, I end up,
    sometimes, with a result of 1991/10/00.
    
    Please let me put the define statement I use in this topic, perhaps
    some of you can provide my with I much better routine.
    
    Thanks in advance,
    	Fons van de Wouw.
    
    
    
	DEFINE FILE ORDERS
	TODAY/I8YYMD     = &YMD + 19000000;
	YESTERDAY/I8YYMD = (TODAY  - 23);
	CHECK/I8YYMD     = IF YESTERDAY EQ 19910100 THEN 19911231 ELSE
	                   IF YESTERDAY EQ 19910200 THEN 19910131 ELSE
	                   IF YESTERDAY EQ 19910300 THEN 19910228 ELSE
	                   IF YESTERDAY EQ 19910400 THEN 19910331 ELSE
	                   IF YESTERDAY EQ 19910500 THEN 19910430 ELSE
	                   IF YESTERDAY EQ 19910600 THEN 19910531 ELSE
	                   IF YESTERDAY EQ 19910700 THEN 19910630 ELSE
	                   IF YESTERDAY EQ 19910800 THEN 19910731 ELSE
	                   IF YESTERDAY EQ 19910900 THEN 19910831 ELSE
	                   IF YESTERDAY EQ 19911000 THEN 19910930 ELSE
	                   IF YESTERDAY EQ 19911100 THEN 19911031 ELSE
	                   IF YESTERDAY EQ 19911200 THEN 19911130 ELSE
	                      YESTERDAY;
	ORST_ODT_H/I8YYMD = (EDIT(EDIT(ORST_ODT_H,'99999999')));
	DIF/I4 = YMD(CHECK,ORST_ODT_H);
	END
	TABLE FILE ORDERS
	PRINT
    	  DECNO
	  ORST_ODT_H
	    IF SRC_SYS_CD EQ 'COMAND'
	    IF DIF GE '0'
	HEADING CENTER
	"Today is <TODAY and Yesterday is was <YESTERDAY but should be <CHECK "
	"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</2"
	ON TABLE HOLD AS DATE1 FORMAT DOC
	END
470.9make your choiceMLCADG::FERRARIFThu Oct 24 1991 06:5045
    	
    Hi,
    
    you can use one of the following:

    
    1) see .1
    
    2) a bit complicated
    
DEFINE FILE ORDERS
...
TODAY/I6= &YMD;
GGARR/I6=DAYMD (TODAY, 'I6');
GGARR=GGARR - 23;
YESTERDAY/I6=DTYMD (GGARR,'I6');
YESTERDAY2/I8=YESTERDAY + 19000000;
...
END
-*

	TODAY     	= is the date of today in format YYMMDD
	GGARR           = convert date (this century) into number of days,
		  	  from 01-jan-1900 to 'today', obtained using subr DAYMD
	GGARR=GGARR-23  = subtract 23 days form number of days ...
	YESTERDAY  	= convert number of days into date (this century) in
			  format YYMMDD
	YESTERDAY2 	= obtain date in format YYYYMMDD

    
    3) very simple
    
DEFINE FILE ORDERS
...
TODAY/I6YMD = &YMD;
YESTERDAY/I6= TODAY - 23;
YESTERDAY2/I8 = YESTERDAY + 19000000;
...
END
    
    	
	Ciao 
	Fabio.