× 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.



A date field is always stored as scaliger no. The date format is only used
to make the scaliger no readable. The format to be used depends on the
current date format within the job.

A date field in an SQL table is defined simply with the data type DATE
(there is NO format keyword!).
When inserting a date into a date field in a table, SQL can convert
character sting representing a date in one of the following formats
YYYY-MM-DD, DD.MM.YYYY, MM/DD/YYYY. The date format to be used for the
character string does not need to match the current job's date format.

Just try the following:
CREATE TABLE YourSchema.YourTable
(YourDate Date Not NULL Default);

Insert into YourSchema.YourTable
Values('2015-12-31'), ('31.12.2015'), ('12/31/2015');;

When using date or time fields in RPG, the SQL precompiler generates
additional workfields. The date and time format for these work fields is NOT
adopted from the defined RPG host variables, but from the compile options
DATFMT, TIMFMT. The default value for DATFMT is *JOB and quite often the
current job's date format is a date format with a 2 digit year.
If your original RPG variable is defined with date format *ISO and
initialized with the *Loval (0001-01-01), and you compile the embedded SQL
program with default options, your RPG program will crash as soon as the
host variable content is moved into the additional precomiler work field.

The easiest way to avoid those problems is to predefine the date format (to
any of an date format with a 4 digit year) in an SET OPTION statement
(H-specs for SQL) at the beginning of your source code. Example:

DCL-S YourDate DatFmt(*ISO);

Exec SQL Set Options DatFmt=*ISO;

YourDate = *Loval;
Exec SQL Insert Into YourSchema.YourTable Values(:YourDate);

YourDAte = D'2015-12-31';
Exec SQL Insert into YourSchema.YourTable Values(:YourDate);

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von Booth
Martin
Gesendet: Saturday, 26.12 2015 05:00
An: RPG programming on the IBM i / System i
Betreff: RPG embedded SQL - how to define a date field

How do I define a date field, and populate it with ISO dates?
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.



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.