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

How to get julian date from given date


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
veena_nagesh2002
Warnings : 1

Active User


Joined: 07 May 2005
Posts: 110
Location: hyderabad

PostPosted: Wed Nov 05, 2008 7:28 pm
Reply with quote

The below clist code will give us the julian day of the current date
SET &JDAT = &SUBSTR(4:5,&SYS4DATE)

then how to get julian date of the input given date, if my given input is like

ex : year : 2008
month : 01
day : 11
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Nov 05, 2008 7:33 pm
Reply with quote

why don' t You start using REXX...
all these conversion functions are built into the language
Back to top
View user's profile Send private message
veena_nagesh2002
Warnings : 1

Active User


Joined: 07 May 2005
Posts: 110
Location: hyderabad

PostPosted: Wed Nov 05, 2008 7:38 pm
Reply with quote

I am not aware of rexx, hence i am using the clist.

Could you please give me the rexx function for the above
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Nov 05, 2008 7:54 pm
Reply with quote

herse is a link to tso and rexx docs
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/Shelves/IKJOSE20
( not the latest one but enough to get started )

for the current docs start from
www-03.ibm.com/systems/z/os/zos/bkserv/index.html#other_pubs
and choose the path relevant to Your software level
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Wed Nov 05, 2008 10:53 pm
Reply with quote

Quote:
why don' t You start using REXX...
all these conversion functions are built into the language


To my "current" knowledge - maybe I need an update class - there is no direct function
to convert a date from i.e. a gregorian to a julian date.

Here what I am using
Code:
 
DatGrg = '20081105'
ddd = Date('D',DatGrg,'S')
DatJul  = Substr(DatGrg,3,2)!!ddd


Cheers
Pierre
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Nov 05, 2008 11:11 pm
Reply with quote

Hi Pierre,
You are right!!

but my comment was more general, about REXX function richness...

anyway is better two date calls and a substr in REXX
rather than carrying on all the computation in CLIST icon_biggrin.gif
Back to top
View user's profile Send private message
cpuhawg

Active User


Joined: 14 Jun 2006
Posts: 331
Location: Jacksonville, FL

PostPosted: Wed Nov 05, 2008 11:58 pm
Reply with quote

Here is some REXX code for julian conversion. It should be placed in a REXX library. This REXX will convert from julian to gregorian or gregorian to julian.

Entering TSO JULIAN provides instructions on how to use. It allows for leap years, so you can enter any julian or gregorian date and receive the converted date.

Code:

/* Rexx */                                                     
/* ---------------------------------------------- */           
/* DATECONV - convert Julian date to Gregorian    */           
/*            and visa versa. If I/P is 5 pos.    */           
/*            it is assumed to be a Julian date   */           
/*            and a Gregorian date will be gen-   */           
/*            erated. If the I/P is 8 pos., it    */           
/*            is assumed to be a Gregorian date   */           
/*            and a Julian will be returned.      */           
/* ---------------------------------------------- */           
/*  Here's where we'll check for Tracing!     */               
/* ------------------------------------------ */               
  address ISPEXEC "CONTROL ERRORS CANCEL";                     
  prevrc = rc;                                                 
  Address ISPEXEC "VGET (SPFDBUG) PROFILE";                   
  If Rc ¬= 0 Then Spfdbug = N                                 
  If Spfdbug = Y Then Trace "r"                               
    Else                                                       
      Do                                                       
        Trace "o";                                             
        OUTTRAP("OUTPUT",0)                                             
        End;                                                           
/* ------------------------------------------ */                       
/* MAKEBUF */                                                           
Parse UPPER Arg Ip_Date Out_Type xtra;                                 
If IP_DATE="" then say "Julian to Gregorian date requires YYDDD input" 
If IP_DATE="" then say "i.e. TSO JULIAN 05123                         "
If IP_DATE="" then say "Gregorian to Julian date requires YY/MM/DD input
If IP_DATE="" then say "i.e. TSO JULIAN 05/05/23                       
If IP_DATE="" then exit                                                 
If Ip_Date = "" Then Signal JulConvert                                 
If Length(Ip_Date) = 5 Then                                             
  Do                                                                   
    JULD = Ip_Date                                                     
    DT = G                                                             
    Signal Second                                                       
    End;                                                               
   Else Date = Ip_Date                                                 
JulConvert:                                                             
   DT = J                                                               
Second:                                                                 
   ZERO = 0                                                   
   SW = 0                                                     
   If DT ¬= J  Then                                           
     Do                                                       
       YEAR = Substr(JULD,1,2)                                 
       JULN = Substr(JULD,3,3)                                 
       End;                                                   
     Else Do                                                   
       YEAR = Substr(DATE,1,2)                                 
       MONTH = Substr(DATE,4,2)                               
       DD = Substr(DATE,7,2)                                   
       End;                                                   
Chg_Year:                                                     
 TYEAR = YEAR + 1900                                           
 BYEAR = (TYEAR / 4)                                           
 XYEAR = TRUNC(BYEAR)                                         
 ZYEAR = BYEAR - XYEAR                                         
 If ZYEAR > 0 Then Signal Start                               
 SW = 1                                                       
 Signal Start2                                                 
                                                               
Start:                                                           
Push    0   31  59  90 120 151 181 212 243 273 304 334           
Signal Cont                                                     
                                                                 
Start2:                                                         
Push    0   31  60  91 121 152 182 213 244 274 305 335           
                                                                 
Cont:                                                           
Parse Pull N.1 N.2 N.3 N.4 N.5 N.6 N.7 N.8 N.9 N.10 N.11 N.12   
                                                                 
If DT = G Then Signal Greg_Convert                               
                                                                 
 MN = (MONTH * 1)                                               
 DD = (DD + Value(N.MN))                                         
 DD = 00||DD                                                     
 DD = Right(DD,3)                                               
 JULI = YEAR||DD"      YYJJJ format"                             
                                                                 
DateOut = JULI                                                   
Signal PutOut;                                                   
/* Say "Here tis ===>" JULI                                     
/* DROPBUF */                                                   
 Exit (0) */                                                   
                                                               
Greg_Convert:                                                   
 JULN = (JULN * 1)                                             
 NUM = 12                                                       
                                                               
Do Forever                                                     
   If JULN > Value(N.NUM) Then Signal Date                     
      Else NUM = NUM - 1                                       
      End;                                                     
                                                               
Date:                                                           
 MONTH = NUM                                                   
 CALC = Value(N.NUM)                                           
 DAY = JULN - Value(CALC)                                       
 If DAY < 10 Then DAY = 0||DAY                                 
 If MONTH < 10 Then MONTH = 0||MONTH                           
 GRED =  YEAR||"/"||MONTH||"/"||DAY||"     YY/MM/DD format"     
DateOut = GRED                                             
Signal PutOut;                                             
/* Say "Here tis ===>" GRED                                 
/*   DROPBUF  */                                           
   Exit (0); */                                             
                                                           
/* --------How do we show the Output?----------- */         
PutOut:                                                     
  Select;                                                   
    When Abbrev('DISPLAY',Out_Type) Then                   
      Say DateOut;                                         
    When Abbrev('STACK',Out_Type) Then                     
      Push DateOut;                                         
    When Abbrev('VARIABLE',Out_Type) Then                   
      Do                                                   
        DATECONV = DateOut                                 
        Address ISPEXEC "VPUT (DATECONV)"                   
        End;                                               
    Otherwise Say DateOut;                                 
    End;                                                   
                                                           
/* --------Go Away------------------------------ */       
/* DROPBUF; */                                             
Exit (0);                                                 


Enjoy!
Back to top
View user's profile Send private message
veena_nagesh2002
Warnings : 1

Active User


Joined: 07 May 2005
Posts: 110
Location: hyderabad

PostPosted: Thu Nov 06, 2008 12:28 pm
Reply with quote

The given clist code is poping below output, why i am not getting julian day

Code:
SET &DATGRG = '20081105'               
SET &DDD = DATE('D',DATGRG,'S')       
SET &DATJUL  = SUBSTR(DATGRG,3,2)!!DDD
                                       
WRITENR  &DATGRG                       
WRITE                                 
WRITENR  &DDD                         
WRITE                                 
WRITENR  &DATJUL                       

OUTPUT :
'20081105'             
DATE('D',DATGRG,'S')   
SUBSTR(DATGRG,3,2)!!DDD


Edited: Please use BBcode when You post some code, that's rather readable...Anuj
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Thu Nov 06, 2008 10:32 pm
Reply with quote

Code:
SET &DDD = DATE('D',DATGRG,'S')


Date is not a CLIST function. It is a rexx function. Everyone is giving you advice to use rexx. Please take our advice.
Back to top
View user's profile Send private message
veena_nagesh2002
Warnings : 1

Active User


Joined: 07 May 2005
Posts: 110
Location: hyderabad

PostPosted: Tue Nov 18, 2008 9:29 am
Reply with quote

sorry for the late reply and also accept my apologies since have no idea whether i can use the same post.

Note : Have started using rexx

Q ::: How to avoid suppressing of leading zero in Julian date


Code:
DatGrg = '20090228'                 
say DatGrg                          /* output : 20090228
ddd = Date('D',DatGrg,'S')         
say ddd                             /* output : 59   but i need 059    
DatJul  = Substr(DatGrg,1,4)||ddd                                       
say datjul                          /* output : 200959  but in need 2009059
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Nov 18, 2008 12:39 pm
Reply with quote

This gives a two year and three day Julian date from Gregorian input. You can easily change it to give yyyyddd format too.
Code:

DATEIN = '20061010'                                     
ABC = DATE('D',DATEIN,'S')                             
JDAT = RIGHT(SUBSTR(DATEIN,3,2),2,'0')||RIGHT(ABC,3,'0')
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Tue Nov 18, 2008 12:45 pm
Reply with quote

Too late, Expat. icon_smile.gif
Already given above.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Nov 18, 2008 3:24 pm
Reply with quote

Aaaaaaaaaaaaah Pierre, so why is the OP saying that the leading zero from the day part of the Julian date is missing ?

That is why I put the RIGHT functions in my code to ensure that the leading zeros remain.
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Tue Nov 18, 2008 3:29 pm
Reply with quote

I missed that.

Expat - Ped 1 - 0

icon_rolleyes.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Nov 18, 2008 3:47 pm
Reply with quote

Too many Leffe at the weekend ?
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Need help to append a date&tsp at... DFSORT/ICETOOL 9
No new posts Fetch data from programs execute (dat... DB2 3
Search our Forums:

Back to Top