Hi,
I am beginner to Natural language and I have a requirement in which I need to calculate days between two given dates.
Does Natural language has any inbuilt functions to do the same??? If not, Can any one please help me out the best possible way to achieve it.
Regards,
Rummylion.
Days Caluclation between two dates
- Akatsukami
- Global moderator
- Posts: 1058
- Joined: Sat Oct 16, 2010 2:31 am
- Skillset: Rexx, JCL, DB2/SQL, TSO/ISPF, PL/I
- Referer: ibmmainframes
- Location: Bloomington, IL
- Contact:
Re: Days Caluclation between two dates
Can the LE date manipulation functions be called from Natural?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
-
- Posts: 3
- Joined: Thu Jun 21, 2012 2:53 pm
- Skillset: COBOL,JCL,DB2,NATURAL,REXX
- Referer: website
Re: Days Caluclation between two dates
No, I am supposed to write this using Natural language only.
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Days Caluclation between two dates
Hello and welcome to the forum,
Maybe Ralph Zbrog will see this and reply.
Here is something he posted in another forum:
With this guidance and the documentation, hopefully you can proceed.
Maybe Ralph Zbrog will see this and reply.
Here is something he posted in another forum:
. . . there is a common practice is to convert your external date variable (eg: yyyymmdd) to a temporary D-format variable using a MOVE EDITED. The D-format makes comparisons and computations simple and straightforward.
With this guidance and the documentation, hopefully you can proceed.
Hope this helps,
d.sch.
d.sch.
- prino
- Posts: 641
- Joined: Wed Mar 11, 2009 12:22 am
- Skillset: PL/I - CICS - DB2 - IDMS - REXX - JCL, most in excess of three decades
- Referer: Google
- Location: Vilnius, Lithuania
- Contact:
Re: Days Caluclation between two dates
Code: Select all
/**********************************************************************
* Convert a date to a Julian Day Number *
**********************************************************************/
cj: proc(fld, flm, fly, jdn);
dcl fld float (16);
dcl flm float (16);
dcl fly float (16);
dcl jdn fixed bin (31);
fly = fly + (flm - 2.85) / 12;
jdn = floor(
floor(
floor(367 * fly) - 1.75 * floor(fly) + fld) -
0.75 * floor(fly / 100)) + 1721115;
end cj;
/**********************************************************************
* Convert a Julian Day Number to a date *
**********************************************************************/
jc: proc(jdn, dd, mm, yyyy);
dcl jdn fixed (7);
dcl dd fixed (3);
dcl mm fixed (3);
dcl yyyy fixed (5);
dcl flc float (16);
dcl fln float (16);
fln = jdn - 1721119.2;
flc = trunc(fln / 36524.25);
fln = fln + flc - trunc(flc / 4);
yyyy = trunc(fln / 365.25);
fln = fln - trunc(365.25 * yyyy) - 0.3;
mm = trunc(fln / 30.6);
dd = trunc(fln - 30.6 * mm + 1);
if mm > 9 then
do;
mm = mm - 9;
yyyy = yyyy + 1;
end;
else
mm = mm + 3;
end jc;
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
robert.ah.prins @ the.17+Gb.Google thingy
- RGZbrog
- Posts: 101
- Joined: Mon Nov 23, 2009 1:34 pm
- Skillset: Natural, Adabas, Predict, Natural Security, Construct, EntireX, SPoD, NaturalONE
- Referer: SAG Developer Forum
- Location: California, USA
- Contact:
Re: Days Caluclation between two dates
Yes, Natural can handle date calculations natively, using any combination of date literals, date-format variables, or system date variable.
Alpha format date values must be converted to internal date format prior to the calculations.
Note that my date literals may not compile on your system, as the date format will be customized for your location. My Natural system expects date literals in the form D'MM/DD/YYYY'.
Code: Select all
DEFINE DATA LOCAL
1 #FROM (D) INIT <D'06/15/2012'>
1 #TO (D) INIT <D'06/18/2012'>
1 #DAYS (N3)
END-DEFINE
#DAYS := D'06/18/2012' - D'06/15/2012'
WRITE #DAYS 'days between D"06/18/2012" and D"06/15/2012"'
*
#DAYS := #TO - #FROM
WRITE #DAYS 'days between #FROM and #TO'
*
#DAYS := *DATX - D'06/15/2012'
WRITE #DAYS 'days between *DATX and D"06/15/2012"'
END
Code: Select all
Page 1 06/24/12 00:19:56
3 days between D'06/18/2012' and D'06/15/2012'
3 days between #FROM and #TO
9 days between *DATX and D'06/15/2012''
Alpha format date values must be converted to internal date format prior to the calculations.
Note that my date literals may not compile on your system, as the date format will be customized for your location. My Natural system expects date literals in the form D'MM/DD/YYYY'.
-
- Posts: 3
- Joined: Thu Jun 21, 2012 2:53 pm
- Skillset: COBOL,JCL,DB2,NATURAL,REXX
- Referer: website
Re: Days Caluclation between two dates
Thank you for your help.
-
- Similar Topics
- Replies
- Views
- Last post
-
- 10
- 4271
-
by chillmo
View the latest post
Thu Mar 13, 2025 12:01 am
-
- 8
- 3660
-
by sergeyken
View the latest post
Wed Nov 17, 2021 6:56 pm