If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > date function or package

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-03, 08:39
xuancc xuancc is offline
Registered User
 
Join Date: Jun 2003
Posts: 6
Unhappy date function or package

Hello, all

Is there any procedure or function or package in informix I can use to convert a date type to int or string in dbaccess?

for instance,

table a
col1 serial
col2 date

select <function_name>(col2) from a;

Could anyone help, thanks.
Reply With Quote
  #2 (permalink)  
Old 06-19-03, 10:48
sconway sconway is offline
Registered User
 
Join Date: May 2003
Posts: 3
I assume you want to convert datetime to UNIX Timet value? If so try this...

NOTE: Function will work for IDS but not SE

CREATE FUNCTION spl_datetime_to_unixtimet(
pDatetime DATETIME YEAR TO SECOND
) RETURNING INT;

DEFINE vUnixTimet INTEGER;

-- The maximum Informix second interval precision is 9 digits which is too small
-- to hold the number of seconds since 1970... Therefore, get the number of seconds
-- since 2000-01-01 00:00:00 and add 946684800 to which represents the number
-- of seconds from 1970 to 2000...
--
LET vUnixTimet = ((INTERVAL(0) SECOND(9) TO SECOND
+ (pDatetime - DATETIME(2000-01-01 00:00:00) YEAR TO SECOND)) || "");

RETURN (vUnixTimet + 946684800);
END FUNCTION;
Reply With Quote
  #3 (permalink)  
Old 06-19-03, 13:22
dananio dananio is offline
Registered User
 
Join Date: Mar 2002
Posts: 112
re

You can use '::' to casting datatype
such as
SELECT aa::char(10)
Reply With Quote
  #4 (permalink)  
Old 06-19-03, 22:25
xuancc xuancc is offline
Registered User
 
Join Date: Jun 2003
Posts: 6
Re: re

Quote:
Originally posted by dananio
You can use '::' to casting datatype
such as
SELECT aa::char(10)
Unfortunately, I am using SE not IDS.
Actually, I want to migrate SE to IDS, but seems some date data corrupted. I can't export SE data, it reported 1210 error. I prefer to convert the date data to a int or string type so that I can correct it because I can't directly retreive these corrupted date.

select col1 where col2<'01/01/1000' got a 1210 error.
for example, if there is a routine To_Int(DATE) which can convert DATE to INT, then maybe I can do in this way,
select col1 where To_Int(col2) < 0
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On