Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

REXX MVS - dates from Gregorian to Julian

691 views
Skip to first unread message

Dave Schaeffer

unread,
Apr 9, 1998, 3:00:00 AM4/9/98
to

I'm looking for a routine that will take a Gregorian date, mm/dd/yy, and

convert it to a Julian date of the format, yyyyddd. The system I'm on
is MVS OS/390. Any help would be appreciated.

--
Dave Schaeffer
AlliedSignal Truck Brake Systems
E-Mail: Dave.Sc...@AlliedSignal.com


Robert AH Prins

unread,
Apr 10, 1998, 3:00:00 AM4/10/98
to Dave.Sc...@alliedsignal.com

In article <352D2CFD...@AlliedSignal.com>,

Dave,

We use the following two routines to convert dates to days & back. For your
application, you would use your date & 31/12 of the previous year to obtain
the Julian date.

/*
* CJ converts a date in yyyy-mm-dd format to its corresponding Julian
* Day Number (i.e. days elapsed since 01/01/4713 BC...)
*/
cj:
arg dmy

parse value dmy with yyyy '-' mm '-' dd

yy = yyyy + (mm - 2.85) / 12

if 10000 * yyyy + 100 * mm + dd <= 15821004 then
c = 0.75 * 2
else
c = 0.75 * trunc(yy / 100)

jdn = trunc(,
trunc(,
trunc(367 * yy) - 1.75 * trunc(yy) + dd) - c) + 1721115

return jdn

/*
* JC converts a Julian day number back to a date in dd.mm.yyyy format.
*/
jc:
arg jdn

n = jdn - 1721119.2
c = trunc(n / 36524.25)

if jdn < 2299161 then
n = n + 2
else
n = n + c - trunc(c / 4)

y = trunc(n / 365.25)
n = n - trunc(365.25 * y) - 0.3
m = trunc(n / 30.6)
d = trunc(n - 30.6 * m + 1)

if m > 9 then
do
m = m - 9
y = y + 1
end
else
do
m = m + 3
end

return right(y, 4, '0')'-'right(m, 2, '0')'-'right(d, 2, '0')

Regards,

Robert
--
Robert AH Prins
pri...@wcg.co.uk

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading

Ken MacKenzie

unread,
Apr 10, 1998, 3:00:00 AM4/10/98
to

Dave Schaeffer wrote in message <352D2CFD...@AlliedSignal.com>...


>I'm looking for a routine that will take a Gregorian date, mm/dd/yy, and
>
>convert it to a Julian date of the format, yyyyddd. The system I'm on
>is MVS OS/390. Any help would be appreciated.

If you've got LE/370 (COBOL/370) available, you could do what I did and
write a "stub" routine which calls the "CEE" routines. The "CEE" routines
let you do anything you ever wanted to do to a date!

Tjerk Santegoeds

unread,
Apr 10, 1998, 3:00:00 AM4/10/98
to

On Thu, 09 Apr 1998 16:18:06 -0400, Dave.Sc...@AlliedSignal.com wrote:

:I'm looking for a routine that will take a Gregorian date, mm/dd/yy, and


:
:convert it to a Julian date of the format, yyyyddd. The system I'm on
:is MVS OS/390. Any help would be appreciated.

The following code should do the job.

/*%NoComment REXX *********************************************************
*
* Program : dConv
*
* Programmer : T. Santegoeds.
*
* Dates : 10Apr1998.
* - Initial coding.
*
* Description : This REXX converts Gregorian dates in the format
* mm/dd/yy to a Julian date in de format yyyyddd.
*
***************************************************************************/
Trace OFF

/** We only want one argument. The date */
If Arg() \= 1 Then Do
Say 'Give one argument. A date in Gregorian format (mm/dd/yy).'
Exit 16
End

oldDate = Arg( 1 )

/** Initialize static globals. */
Call Init

/** Check if the given date is in a valid format and range. */
x = FormatCheck( oldDate )

/** Convert the Gregorian date to a Julian date. */
newDate = Convert( oldDate )

/** Display the converted result. */
Say newDate

exit 0 /** Normal exit dConv **/


/*#########################################################################*/
/*############ P R O C E D U R E S E C T I O N #########################*/
/*#########################################################################*/


Init:
/****************************************************************************
*
* Init -- Initialize static variables that might be used throughout the
* program.
*
* Arguments :
* None
*
* Returns :
* Nothing
*
***************************************************************************/

monthdays. = 0 /* In case we access a month out of range */
monthdays.1 = 31
monthdays.2 = 28
monthdays.3 = 31
monthdays.4 = 30
monthdays.5 = 31
monthdays.6 = 30
monthdays.7 = 31
monthdays.8 = 31
monthdays.9 = 30
monthdays.10 = 31
monthdays.11 = 30
monthdays.12 = 31

Return ''

FormatCheck: PROCEDURE EXPOSE monthdays.
/****************************************************************************
*
* FormatCheck -- Check if the given date is in a valid Gregorian format.
* If the date isn't in the correct format exit the program
* with an error message.
*
* Arguments :
* date The date in Gregorian format (mm/dd/yy).
*
* Returns :
* Nothing
*
***************************************************************************/
Arg date

Parse Var date month '/' days '/' year .

/*
* Strip leading zeros. Otherwise we access the wrong stem from the
* monthdays. list.
*/
month = Strip( month, 'L', '0' )
days = Strip( days, 'L', '0' )


If Length( date ) \= 8 | , /* To many characters */
Substr( date, 3, 1 ) \= '/' | , /* Invalid seperator */
Substr( date, 6, 1 ) \= '/' | , /* Invalid seperator */
Datatype( Substr( date, 1, 2 ), 'N' ) \= 1 | , /* Invalid month type */
Datatype( Substr( date, 4, 2 ), 'N' ) \= 1 | , /* Invalid day type */
Datatype( Substr( date, 7, 2 ), 'N' ) \= 1 , /* Invalid year type */
Then Do
Say date "isn't a valid Gregorian date. Use mm/dd/yy."
Exit 16
End


/*
* Now we now know that the format is valid, lets check the ranges.
*/
If month > 12 | month < 1 Then Do
Say date || ", month out of range."
Exit 16
End
If year > 99 Then Do
Say date || ", year out of range."
Exit 16
End

/** Determine the maximum allowed days in the month */
If month = 2 Then
maxdays = monthdays.month + LeapYear( year )
Else
maxdays = monthdays.month

If days > maxdays | days < 1 Then Do
Say date || ", days out of range."
exit 16
End


Return ''

Convert: PROCEDURE EXPOSE monthdays.
/***************************************************************************
*
* Convert -- Convert a date in Gregorian format (mm/dd/yy) to Julian
* format (yyyyddd).
*
* Arguments :
* date The date in Gregorian format (mm/dd/yy).
*
* Returns :
* The date in Julian format (yyyyddd).
*
***************************************************************************/
Arg oldDate

Parse Var oldDate oldMonth '/' oldDay '/' oldYear .

countEnd = oldMonth - 1; newDays = 0
Do i=1 To countEnd
newDays = newDays + monthdays.i
End
newDays = newDays + oldDay

/** If the date falls after February, check if it's a leap year */
If oldMonth > 2 Then
newDays = newDays + LeapYear( oldYear )

/** Convert the two digit year to a four digit year */
newYear = Y2K( oldYear )

Return newYear || newDays

LeapYear: PROCEDURE
/****************************************************************************
*
* LeapYear -- Check if the given year (yy) is a leap year.
*
* Arguments :
* year The year to check in the format yy.
*
* Returns :
* 1 The year is a leap year.
* 0 The year isn't a leap year.
*
***************************************************************************/
Arg year

/** Convert the two digit year to a four digit year */
year = Y2K( year )

Select
When (year // 4) = 0 & ,
(year // 100) = 0 & ,
(year // 400) = 0 ,
Then
leap = 1
When (year // 4) = 0 & ,
(year // 100) = 0 ,
Then
leap = 0
When (year // 4) = 0 Then
leap = 1
Otherwise
leap = 0
End

Return leap

Y2K: PROCEDURE
/****************************************************************************
*
* Y2K -- Convert a two digit year to a 4 digit year.
*
* Arguments :
* year The year in two digits.
*
* Returns :
* The year in four digits.
*
***************************************************************************/
Arg year

If year > 50 Then year = 1900 + year
Else year = 2000 + year

Return year

/* END OF PROGRAM -- dConv ************************************************/


--
Tjerk Santegoeds
Apeldoorn - The Netherlands

Gilbert Saint-flour

unread,
Apr 11, 1998, 3:00:00 AM4/11/98
to

In <352D2CFD...@AlliedSignal.com>, on 04/09/98 at 04:18 PM, Dave
Schaeffer <Dave.Sc...@AlliedSignal.com> said:

>I'm looking for a routine that will take a Gregorian date, mm/dd/yy,
>and convert it to a Julian date of the format, yyyyddd.
>The system I'm on is MVS OS/390.

What release of OS/390 are you running? The DATE function has been
enhanced in TSO/E 2.6 (which, I think, came with OS/390 R3) and can now
convert dates from one format to another.

Gilbert Saint-flour <g...@ibm.net>

Gilbert Saint-flour

unread,
Apr 12, 1998, 3:00:00 AM4/12/98
to

In <352f7dfe$1$tfs$mr2ice@igate>, on 04/11/98 at 10:24 AM, Gilbert
Saint-flour <g...@ibm.net> said:

>What release of OS/390 are you running? The DATE function has been
>enhanced in TSO/E 2.6 (which, I think, came with OS/390 R3) and can now
>convert dates from one format to another.

TSO/E 2.6 came with OS/390 R4, not R3 - sorry about that.

Gilbert Saint-flour <g...@ibm.net>

0 new messages