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 > DataTime Calcule in SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-22-08, 10:38
dicipulofer dicipulofer is offline
Registered User
 
Join Date: Oct 2007
Posts: 55
DataTime Calcule in SQL

Hello..

I'd like to return that query in Hours.. but it return in days...

select dat_fim_ocorrencia - dat_ini_ocorrencia from movapo mov
where mov.cod_empresa = '20' and
mov.dat_refer >= '01/01/2008' and
mov.dat_refer <= '01/01/2008'

It's possible ?
Reply With Quote
  #2 (permalink)  
Old 08-22-08, 16:01
dicipulofer dicipulofer is offline
Registered User
 
Join Date: Oct 2007
Posts: 55
Well,
i'm getting

12202010 0 00:11
12202010 0 00:08

I'd like to convert 0, 00:11 to hours.

How I do this ?
Reply With Quote
  #3 (permalink)  
Old 08-23-08, 20:07
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
where you get this: "12202010 0 00:11" ???
This not appear datetime or interval data type...
do you mean this" 0 00:11" as result?

what data type is dat_fim_ocorrencia and dat_inicio_ocorrencia?
if your result of the calc over the fields is "0 00:11" , to convert to date, the only way what I know, unfortunately there is no direct way.. you need to convert to char and then convert to datetime.
Code:
create temp table tmp1( dt1 datetime year to second, dt2 datetime year to second);

insert into tmp1 values ('2008-12-01 13:01:56', '2008-12-15 09:40:24') ;

select dt1, dt2, dt1-dt2, dt2-dt1 from tmp1 ;

select (dt2-dt1)::char(20), substr((dt2-dt1)::char(20), 11,5)::datetime hour to minute from tmp1;
__________________
________________________________________
César Inacio Martins
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________
Reply With Quote
  #4 (permalink)  
Old 08-23-08, 20:25
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
my mistake.. sorry..

maybe this can help you, but the datatype returned is a interval, to convert to datetime, need to convert to char an than to datetime hour to minute.
But, be careful, because like this example, will return more than 24 hours what obvious is invalid to datetime hour to minute type.
Code:
create temp table tmp1( dt1 datetime year to second, dt2 datetime year to second);

insert into tmp1 values ('2008-12-01 13:01:56', '2008-12-15 09:40:24') ;

select dt1, dt2, dt1-dt2, dt2-dt1 from tmp1 ;

select (dt2-dt1):: interval hour(9) to minute  from tmp1;
will return:
Code:
dt1                 dt2                 (expression)       (expression)

2008-12-01 13:01:56 2008-12-15 09:40:24       -13 20:38:28        13 20:38:28


(expression)

       332:38
__________________
________________________________________
César Inacio Martins
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________
Reply With Quote
  #5 (permalink)  
Old 08-26-08, 13:50
dicipulofer dicipulofer is offline
Registered User
 
Join Date: Oct 2007
Posts: 55
Quote:
Originally Posted by ceinma
maybe this can help you, but the datatype returned is a interval, to convert to datetime, need to convert to char an than to datetime hour to minute.
But, be careful, because like this example, will return more than 24 hours what obvious is invalid to datetime hour to minute type.
Code:
create temp table tmp1( dt1 datetime year to second, dt2 datetime year to second);

insert into tmp1 values ('2008-12-01 13:01:56', '2008-12-15 09:40:24') ;

select dt1, dt2, dt1-dt2, dt2-dt1 from tmp1 ;

select (dt2-dt1):: interval hour(9) to minute  from tmp1;
will return:
Code:
dt1                 dt2                 (expression)       (expression)

2008-12-01 13:01:56 2008-12-15 09:40:24       -13 20:38:28        13 20:38:28


(expression)

       332:38


Thanks This code will be very userfull to me...

But Look the problem that I'm having with dates.
Table x:
A B Result
2008-08-19 17:18 2008-08-19 14:00 0 03:1


The field A and B are datefields... I'm trying do a simple select like

select a,b,a-b from table x

The right result should be 03:18 but it return 03:1....

It's cause for me a lot of problems... It's a date format ?


I found one way to convert 03:60 in hours for example:

60 * 60 = 3600 / 100 = 36.

So I got 3.36.
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