|
The best (IMHO) way to do this... create function CvtNumISOtoDate(indte Numeric(8,0)) returns Date language SQL not fenced deterministic no external action returns null on null input contains SQL set option datfmt=*ISO begin declare INVALID_DATETIME condition for '22007'; declare exit handler for INVALID_DATETIME begin resignal sqlstate '01HD1' set message_text = 'Invalid date/time replaced by NULL'; return NULL; end; return( case indte when 0 then NULL when 99999999 then date('9999-12-31') else date(substr(digits(indte),1,4) concat '-' concat substr(digits(indte),5,2) concat '-' concat substr(digits(indte),7,2)) end ); end; The to use it you just: Select CvtNumISOtoDate(mynumdate) from somefile HTH, Charles Wilt -- iSeries Systems Administrator / Developer Mitsubishi Electric Automotive America ph: 513-573-4343 fax: 513-398-1121 > -----Original Message----- > From: midrange-l-bounces@xxxxxxxxxxxx > [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of > michael@xxxxxxxxxxxxxxxxxx > Sent: Monday, December 05, 2005 11:49 AM > To: Midrange Systems Technical Discussion > Subject: SQL - Cast Numeric to Date > > I have an 8.0 field in a file. I want to do something like this: > > Select Date(Num_Field) as Mydate... > > I can see how to do it with a CAST on a character field - > what do I need > to do for a numeric field in CCYYMMDD format? It's not really ISO...at > least I can't see how to specify no seperators. > > Thanks... > > -- > This is the Midrange Systems Technical Discussion > (MIDRANGE-L) mailing list > To post a message email: MIDRANGE-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/midrange-l > or email: MIDRANGE-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/midrange-l. > >
As an Amazon Associate we earn from qualifying purchases.
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.