View previous topic :: View next topic
|
Author |
Message |
veena_nagesh2002 Warnings : 1 Active User
Joined: 07 May 2005 Posts: 110 Location: hyderabad
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
why don' t You start using REXX...
all these conversion functions are built into the language |
|
Back to top |
|
|
veena_nagesh2002 Warnings : 1 Active User
Joined: 07 May 2005 Posts: 110 Location: hyderabad
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
Back to top |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
Back to top |
|
|
cpuhawg
Active User
Joined: 14 Jun 2006 Posts: 331 Location: Jacksonville, FL
|
|
|
|
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 |
|
|
veena_nagesh2002 Warnings : 1 Active User
Joined: 07 May 2005 Posts: 110 Location: hyderabad
|
|
|
|
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 |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
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 |
|
|
veena_nagesh2002 Warnings : 1 Active User
Joined: 07 May 2005 Posts: 110 Location: hyderabad
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
Too late, Expat.
Already given above. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
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 |
|
|
PeD
Active User
Joined: 26 Nov 2005 Posts: 459 Location: Belgium
|
|
|
|
I missed that.
Expat - Ped 1 - 0
|
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Too many Leffe at the weekend ? |
|
Back to top |
|
|
|