× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Michael - I was doing a two-step process also. Just curious if there is a better way.

It seems very odd that iseries COBOL ILE introduced the FUNCTION CURRENT-DATE as an alpha result - and not as a date or timestamp field.

All the other date functions work with date data types.

Plus, COBOL already had a method to get the current date/time as an alpha field.

Joel


-----Original Message-----
From: COBOL400-L [mailto:cobol400-l-bounces@xxxxxxxxxxxx] On Behalf Of MichaelQuigley@xxxxxxxxxx
Sent: Wednesday, September 14, 2016 12:52 PM
To: cobol400-l@xxxxxxxxxxxx
Subject: Re: [COBOL400-L] COBOL400-L Digest, Vol 14, Issue 41

"COBOL400-L" <cobol400-l-bounces@xxxxxxxxxxxx> wrote on 09/14/2016
01:00:02 PM:
----- Message from "Stone, Joel" <Joel.Stone@xxxxxxxxxx> on Tue, 13
Sep 2016 18:22:36 +0000 -----

To:

"'COBOL Programming on the IBM i (AS/400 and iSeries)'" <cobol400-
l@xxxxxxxxxxxx>

Subject:

[COBOL400-L] COBOL: getting the current date into am *ISO db field

ILE Cobol v7r1

Trying to learn all about date data types and cobol. I can see why
many use the old YYYYMMDD pic x(8) in their db fields!!

Is it possible to acquire the current date AND move it into a db
field in one step? It doesn't seem to be possible; am I missing
something?

DTDUE-DT is defined as *ISO in the db (is there a better choice?)



Using *DATETIME and *DATE as compiler options, the COBOL compiler
data definition sees it as:

06 DTDUE-DT FORMAT DATE '@Y-%m-%d'.
DUE DT
(Date field)



MOVE FUNCTION CURRENT-DATE to DTDUE-DT

Seems to fail; ie it refuses to acknowledge the separators.

Executing the statement at noon today, DTDUE-DT is set to 2016090312

Where the ending "12" is the hours.

I have tried

MOVE FUNCTION CURRENT-DATE ('@Y-%m-%d) to DTDUE-DT

And also

MOVE FUNCTION CURRENT-DATE to DTDUE-DT ('@Y-%m-%d)

But those don't get past the editor :(


Shouldn't COBOL be smart enough to add the date separators "-" if
the target field is defined with them??

Thanks in advance!

Here's the long answer:

The tricky thing is FUNCTION CURRENT-DATE does not produce a date-field
value. It also doesn't support any format codes. It is a 21 character
alphanumeric value with the format YYYYMMDDHHMMSShh+nnmm. (That's my
format coding, I think first part is obvious Year, month, etc. The latter
parts are:
hh - hundredths of a second
+ - UTC (Greenwich Mean Time) + = plus or - = minus
nn - Hours plus or minus UTC/GMT
mm - Additional minutes plus or minus UTC/GMT

------------------

The short answer is you need to do two steps to get it to a date field
with any format other than '@Y%M%D' OR '%Y%M%D'.

Working-storage section.

01 Today format date '@Y%M%D'.

Procedure Division.

move function current-date to Today.

------------------

Then you can move today to any other format date field. My first executed
paragraph in COBOL is a set of initializations. I set up the current date
in a date field named 'Today' and then initialize any other values needed.
It would be nice if there was a function that returned today's date as
date value (and the same for time and timestamp). But that's not provided.

Michael Quigley
Computer Services
The Way International
www.TheWay.org

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.