Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Convert date from YYMMDD to YYYYMMDD format

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
SENTHIL MURUGAAN
Warnings : 1

New User


Joined: 12 Jan 2013
Posts: 28
Location: India

PostPosted: Thu Aug 22, 2013 12:59 pm    Post subject: Convert date from YYMMDD to YYYYMMDD format
Reply with quote

Hi,

Is there any FUNCTION to achieve in cobol to convert date from YYMMDD to YYYYMMDD format.

Thanks,
Senthil
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Thu Aug 22, 2013 1:12 pm    Post subject:
Reply with quote

Any particular problem with posting a COBOL question in the COBOL section 12.gif

I'll move it for you, save you making any effort won't it
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu Aug 22, 2013 2:40 pm    Post subject: Reply to: Date conversion in cobol
Reply with quote

All the intrinsic FUNCTIONs are documented in the manual for your release of COBOL. Have a look.

However, something to do what you want sounds "unlikely", as you need some rules to be able to pull the correct century out of the air. Intrinsic FUNCTIONs never have a "psychic day".
Back to top
View user's profile Send private message
Abhishek Saurabh

New User


Joined: 25 Aug 2010
Posts: 23
Location: Pune, India

PostPosted: Thu Aug 22, 2013 3:46 pm    Post subject: Reply to: Date conversion in cobol
Reply with quote

This should work fine....

COMPUTE WS-DATE1 = FUNCTION DATE-TO-YYYYMMDD(130822)
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1738
Location: Bloomington, IL

PostPosted: Thu Aug 22, 2013 4:03 pm    Post subject:
Reply with quote

Do you know how the century window is defined, Abhi-kun? If so, why didn't you explain it?
Back to top
View user's profile Send private message
Abhishek Saurabh

New User


Joined: 25 Aug 2010
Posts: 23
Location: Pune, India

PostPosted: Thu Aug 22, 2013 5:41 pm    Post subject: Reply to: Date conversion in cobol
Reply with quote

Hi Akatsukami..
I will be glad to explain the "century window" used in the above function.. It's just that the original question was pretty simple and straight-forward, so I also gave a simple and straight answer..

Well.. for the benefit of anyone who is not clear about the function I am copying an excerpt from IBM's COBOL Language Reference
-------------------------------------------------------------------------------------
The DATE-TO-YYYYMMDD function converts argument-1 from a date with a
2-digit year (YYnnnn) to a date with a 4-digit year (YYYYnnnn). Argument-2,
when added to the year at the time of execution, defines the ending year of a
100-year interval, or sliding century window, into which the year of argument-1
falls.

The function type is integer.

Format
FUNCTION DATE-TO-YYYYMMDD(argument-1[,argument-2] )
argument-1
Must be zero or a positive integer less than 1,000,000.
argument-2
Must be an integer. If argument-2 is omitted, the function is evaluated
assuming the value 50 was specified.
-------------------------------------------------------------------------------------

In my example, I had not taken argument-2, hence the default of 50 was applicable..
Let me try to make it more clear through two examples:
Example.1:
COMPUTE WS-DATE1 = FUNCTION DATE-TO-YYYYMMDD(130822,110)
Here, 13 is the year but to determine the century it will add 110 to the current year, which comes out to be 2123 (2013+110), which will now be considered as the last year of the current century in effect, so the only possible value for year can be 2113 (since we are considering the century from 2024 to 2123)..

Example.2:
COMPUTE WS-DATE1 = FUNCTION DATE-TO-YYYYMMDD(130822,50)
(Please note 50 is also the default value if arg-2 is not specified)
Here, 13 is the year but to determine the century it will add 50 to the current year, which comes out to be 2063 (2013+50), which will now be considered as the last year of the current century in effect, so the only possible value for year can be 2013 (since we are considering the century from 1964 to 2063)..

I hope I have made this clear enough.... icon_smile.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Thu Aug 22, 2013 5:59 pm    Post subject: Reply to: Date conversion in cobol
Reply with quote

Abhishek Saurabh,

From any professional data environment, two-digit years are nuts, are they not?

If the dates are new dates anyway, for 97 years just using the current century will work.

If the date is a birth-date, the default "window" will not be enough.

I haven't checked but suspect that the date FUNCTIONs spend tedious amounts of time calling LE routines. This may not be a problem.

I can't see the point in using a FUNCTION just to save 12 seconds of coding.
Back to top
View user's profile Send private message
Abhishek Saurabh

New User


Joined: 25 Aug 2010
Posts: 23
Location: Pune, India

PostPosted: Thu Aug 22, 2013 6:16 pm    Post subject: Reply to: Date conversion in cobol
Reply with quote

Bill Woodger,

Yes, I would agree that keeping date values with two-digit years is not a very good option. And I guess this has been realized by many in recent years. However, if one already has dates in this format, there got to be some way to convert. Using the above function is one way. Any other (better) way would definitely be more welcome..

To take the specific example of birth-date that you quoted....yes, the default window may not be enough. So, one would require to decide upon a relevant value of 'argument-2'.. and just to add, this value can be negative also, for example....
COMPUTE WS-DATE1 = FUNCTION DATE-TO-YYYYMMDD(130822,-50)
In this case, the century in effect will be 1864 to 1963..
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Thu Aug 22, 2013 6:23 pm    Post subject:
Reply with quote

Abhishek Saurabh, you provided a simplistic answer to the obvious question. HOWEVER, you did not do the research to find out what kind of date needed to be converted -- you just replied. As such, without knowing all of the details, your answer is incorrect. Furthermore, without knowing all of the details (such as whether SENTHIL MURUGAAN is dealing with birth dates of people that are 21 years or older, for example) -- your revised answer is STILL incorrect. You cannot set the year window without knowing the impact of using that window.

Granted, SENTHIL MURUGAAN posted a really bad question -- the type of date, and the possible range that the 2-digit year represents should have been included in the original post -- but that does not excuse you, as a responder, from making sure that your answer is accurate. You have failed in doing this.
Back to top
View user's profile Send private message
SENTHIL MURUGAAN
Warnings : 1

New User


Joined: 12 Jan 2013
Posts: 28
Location: India

PostPosted: Thu Aug 22, 2013 6:43 pm    Post subject:
Reply with quote

Hi Abhishek,

Thanks for your suggestion. I will try with provided "COMPUTE WS-DATE1 = FUNCTION DATE-TO-YYYYMMDD" Syntax to check on it.

Robert,

I am dealing with Treatment undergone dates and not birth dates. Also i am not sure of the date range.

Thanks,
Senthil
Back to top
View user's profile Send private message
Abhishek Saurabh

New User


Joined: 25 Aug 2010
Posts: 23
Location: Pune, India

PostPosted: Thu Aug 22, 2013 6:52 pm    Post subject:
Reply with quote

Hi Senthil,

You are welcome. Please try and let us know here if you could fulfill your requirement.

Hi Robert,
First of all, if my way of answering was not good enough, I am sorry.. Hopefully, I'll improve.

Now, as far as keeping my answer simplistic and general is concerned, that was intentional. The original question by SENTHIL MURUGAAN was simple "Is there a function to achieve a requirement", so I gave a simple answer with a simple example.. Then, to make the logic of century window more clear, I tried to be more descriptive (with additional examples).. Yes, the answer was again general because my intention was to make clear the syntax and the underlying logic.
Now, what is the exact requirement, what is the exact scenario, what is the possible range of dates, whether the dates are birth-dates or some historic dates or some futuristic dates, I don't know, and I don't think I need to know. I would leave it to Senthil to use this basic information for his specific case and try to fulfill his requirement, and if he is not able (or able) to do so he can definitely post the updates, and we can continue the discussion accordingly..
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1738
Location: Bloomington, IL

PostPosted: Thu Aug 22, 2013 7:01 pm    Post subject:
Reply with quote

SENTHIL MURUGAAN wrote:
I am dealing with Treatment undergone dates and not birth dates. Also i am not sure of the date range.

So it seems likely that you would want a second argument of zero, yes?
Back to top
View user's profile Send private message
SENTHIL MURUGAAN
Warnings : 1

New User


Joined: 12 Jan 2013
Posts: 28
Location: India

PostPosted: Fri Aug 23, 2013 12:50 pm    Post subject:
Reply with quote

Hi Abhishek,

I tried with "COMPUTE WS-OUT-DT = FUNCTION DATE-TO-YYYYMMDD(ws-inpt-dt)" Syntax as per your suggestion and it worked fine as expected.
WS-INPT-DT PIC 9(6)
WS-OUT-DT PIC 9(8)

Thanks a lot.

But i do not have idea on whether i need to specify second argument as Zero as stated by Akatsukami. At present I am not using 2nd argument since it is working fine. But can u pls explain whether second arguement as '0' is required?

Thanks,
Senthil
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Fri Aug 23, 2013 12:54 pm    Post subject:
Reply with quote

Try with a date before the year 2000, e.g. 981230

This may not be a problem to you now, as you may not receive such data, but perhaps a little forward thinking as to what will happen in the future when a century or millenium changes.
Back to top
View user's profile Send private message
SENTHIL MURUGAAN
Warnings : 1

New User


Joined: 12 Jan 2013
Posts: 28
Location: India

PostPosted: Fri Aug 23, 2013 3:27 pm    Post subject:
Reply with quote

Hi expat,

I tried with the below dates and it were fine. I am not sure upto which futuristic date it will work, but from below data it shows that it will surely work upto 2060. anyway i will be dealing with only dates in 20th century and not 19th century for my reqmt.

Code:

INPUT  DT: 180512   
OUTPUT DT: 20180512
INPUT  DT: 650613   
OUTPUT DT: 19650613
INPUT  DT: 690725   
OUTPUT DT: 19690725
INPUT  DT: 510726   
OUTPUT DT: 20510726
INPUT  DT: 981230   
OUTPUT DT: 19981230
INPUT  DT: 601230   
OUTPUT DT: 20601230


Thanks,
Senthil
Back to top
View user's profile Send private message
Abhishek Saurabh

New User


Joined: 25 Aug 2010
Posts: 23
Location: Pune, India

PostPosted: Fri Aug 23, 2013 5:09 pm    Post subject:
Reply with quote

Hi Senthil,

Good to know that the suggestion worked for you..
However, you appear to be confused about the 2nd argument and whether you need it or not.. Well, whether you need it or not depends on what range of dates you are expected to handle, and you need to be clear about the impact of using the 2nd argument..
As you said, you are not using anything in 2nd argument, that means it will take default value of 50 (as menioned in my earlier post), which means the current date (whatever it is) lies in the middle of the current century in effect, so all the dates 50 years before and after the current date should work fine.. However, if you are planning to use 0 for the argument, it would mean the function would work fine only for current date and past date, any future date won't be handled correctly..
So, as I said please be clear about the impact of using the argument value and be clear about the range of values your program is expected to handle.. That would avoid any errors/unexpected outputs..
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1712
Location: UK

PostPosted: Tue Sep 03, 2013 12:00 am    Post subject:
Reply with quote

Please note that we are in the 21st century now - not the 20th century.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts TOT & DATE parameter in ICEMAN hemanthj642 DFSORT/ICETOOL 4 Mon Nov 14, 2016 5:19 am
No new posts convert PD to ZD ram_vizag DFSORT/ICETOOL 5 Sat Nov 05, 2016 3:06 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us