Unix Technical Forum

how to add time portion in a date field

This is a discussion on how to add time portion in a date field within the Informix forums, part of the Database Server Software category; --> In informix, I have a date field (year to day) only in a table, I want add 23 hrs ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-16-2008, 02:44 PM
vchu via DBMonster.com
 
Posts: n/a
Default how to add time portion in a date field

In informix,

I have a date field (year to day) only in a table, I want add 23 hrs and 59
mintues and show it in the output. do we have somthing like this??

select extend(c.date, year to day) + "23:59" from contract c;


p.s. c.date is year to day only

Thanks
Vchu

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....ormix/200805/1

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-16-2008, 02:44 PM
Holger de Wall
 
Posts: n/a
Default Re: how to add time portion in a date field

from
http://publib.boulder.ibm.com/infoce...oc/sqlr150.htm
---
For example, you cannot subtract an INTERVAL MINUTE TO MINUTE value from
the DATETIME value .... You can, however, use the EXTEND function to
perform this calculation, as the following example shows:

EXTEND (DATETIME (2008-8-1) YEAR TO DAY, YEAR TO MINUTE)
- INTERVAL (720) MINUTE(3) TO MINUTE

Result: DATETIME (2008-07-31 12:00) YEAR TO MINUTE
--

Holger de Wall


vchu via DBMonster.com schrieb:
> In informix,
>
> I have a date field (year to day) only in a table, I want add 23 hrs and 59
> mintues and show it in the output. do we have somthing like this??
>
> select extend(c.date, year to day) + "23:59" from contract c;
>
>
> p.s. c.date is year to day only
>
> Thanks
> Vchu
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 02:44 PM
Superboer
 
Posts: n/a
Default Re: how to add time portion in a date field

sounds like you want to add a day:


create table tessie ( a datetime year to day) ;
insert into tessie values (current);


select a + 1 units day, * from tessie


Superboer.


On 16 mei, 00:34, Holger de Wall <hol...@dewall-net.de> wrote:
> fromhttp://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic...
> ---
> For example, you cannot subtract an INTERVAL MINUTE TO MINUTE value from
> the DATETIME value .... You can, however, use the EXTEND function to
> perform this calculation, as the following example shows:
>
> EXTEND (DATETIME (2008-8-1) YEAR TO DAY, YEAR TO MINUTE)
> - INTERVAL (720) MINUTE(3) TO MINUTE
>
> Result: DATETIME (2008-07-31 12:00) YEAR TO MINUTE
> --
>
> Holger de Wall
>
> vchu via DBMonster.com schrieb:
>
> > In informix,

>
> > I have a date field (year to day) only in a table, I want add 23 hrs and 59
> > mintues and show it in the output. do we have somthing like this??

>
> > select extend(c.date, year to day) + "23:59" from contract c;

>
> > p.s. c.date is year to day only

>
> > Thanks
> > Vchu


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-18-2008, 11:04 PM
tgirsch
 
Posts: n/a
Default Re: how to add time portion in a date field

And if you want EXACTLY 23 hours, 59 minutes, you could do:

SELECT a + 1 units day - 1 units minute, * from tessie

Superboer wrote:
> sounds like you want to add a day:
>
>
> create table tessie ( a datetime year to day) ;
> insert into tessie values (current);
>
>
> select a + 1 units day, * from tessie
>
>
> Superboer.
>
>
> On 16 mei, 00:34, Holger de Wall <hol...@dewall-net.de> wrote:
>> fromhttp://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic...
>> ---
>> For example, you cannot subtract an INTERVAL MINUTE TO MINUTE value from
>> the DATETIME value .... You can, however, use the EXTEND function to
>> perform this calculation, as the following example shows:
>>
>> EXTEND (DATETIME (2008-8-1) YEAR TO DAY, YEAR TO MINUTE)
>> - INTERVAL (720) MINUTE(3) TO MINUTE
>>
>> Result: DATETIME (2008-07-31 12:00) YEAR TO MINUTE
>> --
>>
>> Holger de Wall
>>
>> vchu via DBMonster.com schrieb:
>>
>>> In informix,
>>> I have a date field (year to day) only in a table, I want add 23 hrs and 59
>>> mintues and show it in the output. do we have somthing like this??
>>> select extend(c.date, year to day) + "23:59" from contract c;
>>> p.s. c.date is year to day only
>>> Thanks
>>> Vchu

>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-18-2008, 11:04 PM
vchu via DBMonster.com
 
Posts: n/a
Default Re: how to add time portion in a date field

it is ok if i do this:
select EXTEND (DATETIME (2008-8-1) YEAR TO DAY, YEAR TO MINUTE) - INTERVAL
(720) MINUTE(3) TO MINUTE from contract_ref_num where contract_ref_num =
"10003"

but if I replace 2008-8-1 to ref_date, it is not working
it said "non-numeric character in datetime or interval"

select EXTEND (DATETIME (ref_date) YEAR TO DAY, YEAR TO MINUTE) - INTERVAL
(720) MINUTE(3) TO MINUTE from contract_ref_num where contract_ref_num =
"10003"

please helps

ref_date is a date with length = 10, year to day only
Holger de Wall wrote:
>from
>http://publib.boulder.ibm.com/infoce...oc/sqlr150.htm
>---
>For example, you cannot subtract an INTERVAL MINUTE TO MINUTE value from
>the DATETIME value .... You can, however, use the EXTEND function to
>perform this calculation, as the following example shows:
>
>EXTEND (DATETIME (2008-8-1) YEAR TO DAY, YEAR TO MINUTE)
> - INTERVAL (720) MINUTE(3) TO MINUTE
>
>Result: DATETIME (2008-07-31 12:00) YEAR TO MINUTE
>--
>
>Holger de Wall
>
>vchu via DBMonster.com schrieb:
>> In informix,
>>

>[quoted text clipped - 7 lines]
>> Thanks
>> Vchu


--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums....ormix/200805/1

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-18-2008, 11:04 PM
Jonathan Leffler
 
Posts: n/a
Default Re: how to add time portion in a date field

vchu via DBMonster.com wrote:
> it is ok if i do this:
> select EXTEND (DATETIME (2008-8-1) YEAR TO DAY, YEAR TO MINUTE) - INTERVAL
> (720) MINUTE(3) TO MINUTE from contract_ref_num where contract_ref_num =
> "10003"
>
> but if I replace 2008-8-1 to ref_date, it is not working
> it said "non-numeric character in datetime or interval"
>
> select EXTEND (DATETIME (ref_date) YEAR TO DAY, YEAR TO MINUTE) - INTERVAL
> (720) MINUTE(3) TO MINUTE from contract_ref_num where contract_ref_num =
> "10003"


EXTEND will automatically convert a DATE to a DATETIME YEAR TO DAY, so
you only need to write:

SELECT EXTEND(ref_date, YEAR TO MINUTE) - INTERVAL(720) MINUTE(3) TO
MINUTE FROM ...

The best way to think of the parentheses after DATETIME is as a funny
way of writing quotes for a DATETIME literal - rather than as the
parentheses of a function call. The corresponding standard SQL
notations are DATE '2008-08-01' and TIME '23:12:01' and TIMESTAMP
'2008-08-01 23:12:01'.

--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2008.0229 -- http://dbi.perl.org/

publictimestamp.org/ptb/PTB-3261 sha160 2008-05-17 03:00:03
AE25A5E22AF05851246C636C531BA0D4FC26997C
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:57 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com