IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Amount of days between two dates


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
SlippingJimmy

New User


Joined: 21 Sep 2022
Posts: 10
Location: USA

PostPosted: Fri Dec 09, 2022 11:00 pm
Reply with quote

I am receiving two dates from JCL, and I need to find out how many days are between the two. I've read this but I am not sure it applies to what I need to do.
I've tried converting the date to FIXED BIN 31 after receiving the params and tried this below but when I go from 1 Jan to 1 Feb it gives 100 when it should be 31
Code:

   dcl total1    fixed bin(31);
   total1 = enddate - startdate;
 



I am not sure of the best way to get the number of days between the two dates. Any advice?[/code]
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Dec 09, 2022 11:09 pm
Reply with quote

Quote:
I am receiving two dates from JCL, and I need to find out how many days are between the two
What format are the two dates in? One method would be to separate the years and month/day, convert the month/day to Julian day, do the subtraction of the Julian days, and adjust if different years are involved.

Which, considering this is a forum for professionals, is WAY more information than you should need to resolve the problem.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Fri Dec 09, 2022 11:16 pm
Reply with quote

RTFM!

There are a sjitload of builtin functions in Enterprise PL/I that deal with dates!
Back to top
View user's profile Send private message
SlippingJimmy

New User


Joined: 21 Sep 2022
Posts: 10
Location: USA

PostPosted: Fri Dec 09, 2022 11:46 pm
Reply with quote

Robert Sample wrote:
What format are the two dates in?


the format is YYYYMMDD


Robert Sample wrote:
Which, considering this is a forum for professionals, is WAY more information than you should need to resolve the problem.


I have searched the forum and read the docs. Some of the information is dated and doesn't work. One, in particular, was from 2013 that seemed promising but didn't work
When I ask, it's not because I didn't research.
Back to top
View user's profile Send private message
SlippingJimmy

New User


Joined: 21 Sep 2022
Posts: 10
Location: USA

PostPosted: Fri Dec 09, 2022 11:51 pm
Reply with quote

prino wrote:
RTFM!


What is the meaning of this?

prino wrote:
There are a sjitload of builtin functions in Enterprise PL/I that deal with dates!


True, but none of them give the number of days between the two dates like in COBOL.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Fri Dec 09, 2022 11:57 pm
Reply with quote

SlippingJimmy wrote:
I have searched the forum and read the docs. Some of the information is dated and doesn't work. One, in particular, was from 2013 that seemed promising but didn't work
When I ask, it's not because I didn't research.


"Some of the information is dated…"

We're now in 2022, maybe you should go to the IBM site and look at the PL/I Language Reference for the release of Enterprise PL/I you're now using!

These are, just Cut & Paste from the Enterprise PL/I V6.1 manual, the current date and time processing builtins:

Code:
Table 64. Date/time built-in functions
Function Description

DATE Returns the current date in the pattern YYMMDD.

DATETIME Returns the current date and time in the user-specified pattern or in the default pattern YYYYMMDDHHMISS999.

DAYS Returns the number of days corresponding to a date/time pattern string, or the number of days for today's date.

DAYSTODATE Converts a number of days to a date/time pattern string.

DAYSTOMICROSECS Converts a number of days to a number of microseconds.

DAYSTOSECS Converts a number of days to a number of seconds.

JULIANTOSMF Converts a date from Julian format to SMF format.

MAXDATE Returns the latest date/time value for a specified date/time pattern.

MICROSECS Returns the number of microseconds corresponding to a date/time pattern string, or the number of microseconds for today's date.

MICROSECSTODATE Converts a number of microseconds to a date/time pattern string.

MICROSECSTODAYS Converts a number of microseconds to a number of days.

MINDATE Returns the earliest date/time value for a specified date/time pattern.

REPATTERN Takes a value holding a date in one pattern and returns that value converted to a date in a second pattern.

SECS Returns the number of seconds corresponding to a date/time pattern string, or the number of seconds for today's date.

SECSTODATE Converts a number of seconds to a date/time pattern string.

SECSTODAYS Converts a number of seconds to a number of days.

SMFTOJULIAN Converts a date from SMF format to Julian format.

STCKETODATE Converts a STCKE value to a date/time pattern string.

STCKTODATE Converts a STCK value to a date/time pattern string.

TIME Returns the current time in the pattern HHMISS999.

TIMESTAMP Returns the current time in the pattern YYYY-MM-DDHH.MI.SS.999999.

UTCDATETIME Returns the current Coordinated Universal Time (UTC) in the pattern YYYYMMDDHHMISS999.

UTCMICROSECS Returns the number of microseconds corresponding to the current UTC time.

UTCSECS Returns the current Coordinated Universal Time (UTC) in the Lilian format in seconds.

VALIDDATE Indicates if a string holds a valid date.

WEEKDAY Returns the day of the week corresponding to the current day or specified DAYS value.

Y4DATE Takes a date value with the pattern 'YYMMDD' and returns the date value with the two-digit year widened to a four-digit year.

Y4JULIAN Takes a date value with the pattern 'YYDDD' and returns the date value with the two-digit year widened to a four-digit year.

Y4YEAR Takes a date value with the pattern 'YY' and returns the date value with the two-digit year widened to a four-digit year.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Sat Dec 10, 2022 12:48 am
Reply with quote

Lesson #1 for housewives

Step 1. Convert DATE1 to the number of days. (Function DAYS)

Step 2. Convert DATE2 to the number of days. (Function DAYS)

Step 3. Calculate the difference between two integers. (Operation '-')

https://www.ibm.com/docs/en/epfz/5.3?topic=subroutines-days
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Sat Dec 10, 2022 9:48 am
Reply with quote

SlippingJimmy -

If you are concerned that the responders have perhaps seemed less than helpful, look at your original post:

Code:

dcl total1    fixed bin(31);
total1 = enddate - startdate;
 


You do not show:
1. how you assigned values to your variables
2. what their values are before the code
3. what total1 equals after the assignment statement

PL/I has especially neat statements, GET DATA and PUT DATA, that make it SO easy to intersperse display of intermediate values.

In complicated programs, I used to keep PUT DATA statements scattered at important places in production programs and control their execution by a GET DATA input parameter.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Dec 10, 2022 3:34 pm
Reply with quote

unfortunately the original post shows a poor understanding of date arithmetics

the only way to get 100 as told is to just use a plain subtraction of two dates in the format YYYYMMDD

20220201 - 20220101 ==> 100

icon_rolleyes.gif icon_rolleyes.gif icon_rolleyes.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Adding a trailer with record count an... JCL & VSAM 4
No new posts How to remove remote file older than ... All Other Mainframe Topics 4
No new posts Identify the value if the SUM of the ... SYNCSORT 4
No new posts Dates compare on specific dates using... DFSORT/ICETOOL 2
No new posts Formating of Amount field in CLIST be... CLIST & REXX 9
Search our Forums:

Back to Top