How to convert Julian date format into yyyymmdd date format?

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
User avatar
thamodharan
Member
Posts: 21
Joined: Tue Oct 21, 2008 4:45 pm
Location: chennai

How to convert Julian date format into yyyymmdd date format?

Post by thamodharan » Tue Mar 31, 2009 4:08 pm

Hi friends,

I need to convert the julian date format to yyyy/mm/dd format.
Is there any facility to do this? or Should we write any routine for this?
please let me know if there is any easy way to convert this...

Thanks...
[/b]

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

julian date to YYYYMMDD

Post by Natarajan » Tue Mar 31, 2009 4:20 pm

Hi Thamodharan,

Welcome to mainframegurukul.com

You can convert julian date format ( YYDDD) TO YYYYMMDD format using following intrinsic functions.

Code: Select all

 ws-date-int = FUNCTION INTEGER-OF-DAY(argument-1) 
The INTEGER-OF-DAY function converts a date in the Gregorian calendar from Julian date form (YYYYDDD) to integer date form.

Then use following function, with this value you got from above function.

Code: Select all

 date-YYYY-MM-DD  =   FUNCTION DATE-OF-INTEGER(ws-date-int)
The DATE-OF-INTEGER function converts a date in the Gregorian calendar from integer date form to standard date form (YYYYMMDD).


After that you can use your own logic to add slashes between year, date, day parts.


Let me now, if you have any other questions.
Natarajan
Chennai

User avatar
thamodharan
Member
Posts: 21
Joined: Tue Oct 21, 2008 4:45 pm
Location: chennai

Post by thamodharan » Wed Apr 01, 2009 12:35 pm

Thank you Natarajan for your reply.

Will it be allowable by all the compilers?

My compiler is not accepting the FUNCTION keyword.
what shall i do for that? should i change any compiler options to make FUNCTION acceptable?

Thank you once again.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Wed Apr 01, 2009 3:16 pm

Try using RENT compiler option.

Let me know, if it is not working.
Natarajan
Chennai

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Wed Apr 01, 2009 4:17 pm

Try writing the code omitting the 'FUNCTION' keyword.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Julian date ( YYDDD) format into yyyymmdd date format

Post by Natarajan » Thu Apr 02, 2009 9:41 am

Here is the process to convert Julian date (YYDDD) format into yyyymmdd date format,if you want to code the logic without using functions.


Steps to folllow.

Step 1 - take the year part and find out whether it is leap year or not

Code: Select all

 IF A YEAR DIVISIBLE BY 400
 THEN IT IS A LEAP YEAR.   
 IF A YEAR DIVISIBLE BY 4   
 BUT NOT DIVISIBLE BY 100  
 THEN IT IS A LEAP YEAR.   
 


Step 2 - If it is leap year.. increase the no. of days in Feb by 1

Step 3 - Now we need to find out.. which month we are in.
Take DDD part... which contains the no of day from starting of the year.

check as below to get MM value..
if the value in DDD less than or equal 31.. then month is Jan0
if the value in DDD less than or equal ( 31+ 28 (29, if leap year) )
then the month is Feb
etc....

You better code these numbers in an array, so that while coding
you can use perform to get MM value... without writing too much of code.

Code: Select all

  example - 
   01  months
        05  jan     pic 9(3)  value 0
        05  feb     pic 9(3)  value 31
        05  mar    pic 9(3)  value 59
    etc....
   redefine above structure with an array , so that accessing this data will be easy.

Step 4 - Need to find out day part ...


Example - if the given day fall under in the month of April.
If MM has the value of 4 which means april...
your code should work in such way .. it should subtract 90 ( you can take from above array) from DDD
resultant value will be moved to DD part

In case of Feb, need to subtract 31 from DDD and resultant value will be
moved to DD part. etc...

This logic also can be coded using above array.



calculating century part fully depends upon.. where you will use this code...normally people use window... i.e.,

If YY > 50
MOVE 1900 TO CC-YY
else
MOVE 2000 TO CC-YY
end-if

Let me know, if you need any more help on this.
Natarajan
Chennai

User avatar
thamodharan
Member
Posts: 21
Joined: Tue Oct 21, 2008 4:45 pm
Location: chennai

Post by thamodharan » Wed Apr 08, 2009 1:24 pm

Hi,

Yes its fixed now...
thanks for your quick reply.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Wed Apr 08, 2009 3:20 pm

Let us know, which method you have used.
Natarajan
Chennai

User avatar
thamodharan
Member
Posts: 21
Joined: Tue Oct 21, 2008 4:45 pm
Location: chennai

Post by thamodharan » Thu Apr 09, 2009 12:41 pm

Hi,

First I tried with RENT compiler option. But it was not working that time.
Then I have written a seperate routine as you said. Now its fine...

Thanks,
Thamu.

academyindia4

Topic deleted by Admin

Post by academyindia4 » Wed Jan 27, 2016 8:22 pm

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Sat Jan 30, 2016 11:42 pm

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Sat Jan 30, 2016 11:43 pm

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Feb 01, 2016 10:09 pm

<< Content deleted By Admin >>

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others