Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IBM defines *JUL date format as <em>yy/ddd</em>. It is not commonly used, but is is an available standard format supported on the AS/400. You say you have a string, so the assumption here is that it is stored as CHAR(5), or 5A in DDS.</p> <p>If you column is called <em>jdt</em>, get the right number of digits in your string, in SQL, with: </p> <pre><code> RIGHT(('00000' || TRIM(jdt)),5) </code></pre> <p>Now put the slash in:</p> <pre><code> INSERT( RIGHT(('00000'||TRIM(jdt)),5) ,3,0,'/') </code></pre> <p>DB2/400 can cast this to a real date field, but it will only work properly if you can <code>SET OPTION DATFMT=*JUL</code>. How to do this from C# on Windows would depend on how you are connecting. </p> <p>Let's suppose you can't find the way to set the date format on your connection.</p> <p><strong>Solution:</strong> Create a user defined function [UDF] in DB2. </p> <p>First, choose an appropriate library to store the function in, and set that as your current library. In OS/400 CL, <code>CHGCURLIB yourlib</code>, or in SQL, <code>SET SCHEMA = yourlib</code>. Thus by default anything you create will go into this library. </p> <p>I recommend storing the SQL definition for your UDF in a source member. (Ask if unfamiliar) You can execute the source with the <code>RUNSQLSTM</code> command.</p> <p>Your function definition could look something like this:</p> <pre><code>CREATE FUNCTION CvtJul2Date( jdtin char(5) ) RETURNS DATE LANGUAGE SQL SPECIFIC CVTJUL2DT DETERMINISTIC NO EXTERNAL ACTION CONTAINS SQL RETURNS NULL ON NULL INPUT SET OPTION DATFMT = *JUL BEGIN RETURN( date( insert( right(('00000'||trim(jdtin)),5) ,3,0,'/') ) ); END </code></pre> <p>The *JUL option is scoped to the UDF. Any SQL query that runs on the AS/400 should be able to do this conversion, regardless of the DATFMT of the job (assuming you have put this function in a library which is on that job's library list).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload