Re: Datatype conversion
Posted in 1999
Topics: Third-Party Tools & Monitoring
Lak Nadella wrote:
>
> Hi All,
> I am a newbie to Informix. I need to convert a float datatype field
> into Date. The format of the float field is yyyymmdd.xyz. If not
> directly into a date field, can I convert it into a Char datatype so
> that I can use the MDY function to convert it further into a Date.
> Any ideas???
Well I don't know what the .xyz means, but ignoring that and setting
DBDATE=Y4MD0, I tried:
CREATE TABLE mds
(
fl FLOAT,
dt DATE
);
INSERT INTO mds VALUES(19980301.123, "");
UPDATE mds
SET dt = (TRUNC(fl) || "");
SELECT *
FROM mds
Which gave:
fl dt
19980301.12300 19980301
Or setting DBDATE back to DMY4/, and running:
SELECT *
FROM mds
I got:
fl dt
19980301.12300 01/03/1998
So that should be a start for you.
Cheers,
--
Mark.
+----------------------------------------------------------+-----------+
|Mark D. Stock - Informix SA http://www.informix.com |//////// /|
|mailto:mdstock@informix.com http://www.informix.com/idn |///// / //|
|http://www.iiug.org +-----------------------------------+//// / ///|
| Tel: +27 11 807 0313 |What year 2000 bug? year 2000 bug? |/// / ////|
| Fax: +27 838250 2325 |year 2000 bug? year 2000 bug? year |// / /////|
|Cell: +27 83 250 2325 |2000 bug? year 2000 bug? year 1900 |/ ////////|
+----------------------+-----------------------------------+-----------+
What is described here will work fine if you want to do a schema conversion.
But if you have a need to just convert a float value to a date data type in
ESQL*C program for a retrieved row, then you can retrieve the value into
double variable and then use sprintf statement of C Language with a format
%13.5f. then you can use that character string for conversion to the date
value usign one of the esqlc character string to date conversion function.
thanks,
khem chander.
kchande@yahoo.com
Mark D. Stock wrote:
> Lak Nadella wrote:
> >
> > Hi All,
> > I am a newbie to Informix. I need to convert a float datatype field
> > into Date. The format of the float field is yyyymmdd.xyz. If not
> > directly into a date field, can I convert it into a Char datatype so
> > that I can use the MDY function to convert it further into a Date.
> > Any ideas???
>
> Well I don't know what the .xyz means, but ignoring that and setting
> DBDATE=Y4MD0, I tried:>
> CREATE TABLE mds
> (
> fl FLOAT,
> dt DATE
> );>
> INSERT INTO mds VALUES(19980301.123, "");>
> UPDATE mds
> SET dt = (TRUNC(fl) || "");
>
> SELECT *
> FROM mds>
> Which gave:
>
> fl dt
>
> 19980301.12300 19980301
>
> Or setting DBDATE back to DMY4/, and running:
>
> SELECT *
> FROM mds>
> I got:
>
> fl dt
>
> 19980301.12300 01/03/1998
>
> So that should be a start for you.
>
> Cheers,
> --
> Mark.
>
> +----------------------------------------------------------+-----------+
> |Mark D. Stock - Informix SA http://www.informix.com |//////// /|
> |mailto:mdstock@informix.com http://www.informix.com/idn |///// / //|
> |http://www.iiug.org +-----------------------------------+//// / ///|
> | Tel: +27 11 807 0313 |What year 2000 bug? year 2000 bug? |/// / ////|
> | Fax: +27 838250 2325 |year 2000 bug? year 2000 bug? year |// / /////|
> |Cell: +27 83 250 2325 |2000 bug? year 2000 bug? year 1900 |/ ////////|
> +----------------------+-----------------------------------+-----------+