pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedadding time to a datetime field ... how?
5+ messages / 5 participants
[nested] [flat]
* adding time to a datetime field ... how?
@ 1999-12-15 13:31 The Hermit Hacker <scrappy@hub.org>
0 siblings, 2 replies; 5+ messages in thread
From: The Hermit Hacker @ 1999-12-15 13:31 UTC (permalink / raw)
To: pgsql-sql
I hate coming up with subjects...
I have a table with two fields: start_time::datetime and
acctsessiontime::int4...I want to add the second to the first, to give me
a stop_time...
if I do:
select start_time,start_time+acctsessiontime from log;
I get a stop_time 'acctsessiontime' days after start_time, instead of
'acctsessiontime' seconds later...
Is there some way of telling it to pass seconds instead of days?
Thanks
Marc G. Fournier ICQ#7615664 IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] adding time to a datetime field ... how?
@ 1999-12-15 14:01 Margarit Nickolov <man@developer.digsys.bg>
parent: The Hermit Hacker <scrappy@hub.org>
1 sibling, 1 reply; 5+ messages in thread
From: Margarit Nickolov @ 1999-12-15 14:01 UTC (permalink / raw)
To: The Hermit Hacker <scrappy@hub.org>; +Cc: pgsql-sql
select start_time,start_time+acctsessiontime::timespan from log;
On Wed, 15 Dec 1999, The Hermit Hacker wrote:
>
> I hate coming up with subjects...
>
> I have a table with two fields: start_time::datetime and
> acctsessiontime::int4...I want to add the second to the first, to give me
> a stop_time...
>
> if I do:
>
> select start_time,start_time+acctsessiontime from log;
>
> I get a stop_time 'acctsessiontime' days after start_time, instead of
> 'acctsessiontime' seconds later...
>
> Is there some way of telling it to pass seconds instead of days?
>
> Thanks
>
> Marc G. Fournier ICQ#7615664 IRC Nick: Scrappy
> Systems Administrator @ hub.org
> primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
>
>
> ************
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] adding time to a datetime field ... how?
@ 1999-12-15 16:21 Vladimir Terziev <vlady@school.digsys.bg>
parent: The Hermit Hacker <scrappy@hub.org>
1 sibling, 0 replies; 5+ messages in thread
From: Vladimir Terziev @ 1999-12-15 16:21 UTC (permalink / raw)
To: The Hermit Hacker <scrappy@hub.org>; +Cc: pgsql-sql
Try
select start_time,
abstime_datetime(start_time::abstime + acctsessiontime)
from log;
Regards!
Vladimir
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] adding time to a datetime field ... how?
@ 1999-12-17 00:31 Peter Eisentraut <peter_e@gmx.net>
parent: Margarit Nickolov <man@developer.digsys.bg>
0 siblings, 1 reply; 5+ messages in thread
From: Peter Eisentraut @ 1999-12-17 00:31 UTC (permalink / raw)
To: Margarit Nickolov <man@developer.digsys.bg>; +Cc: The Hermit Hacker <scrappy@hub.org>; pgsql-sql
On 1999-12-15, Margarit Nickolov mentioned:
> select start_time,start_time+acctsessiontime::timespan from log;
Wow, that is really weird. I would consider it confusing behaviour at
best if an explicit cast interprets an int as seconds whereas an implicit
conversion thinks it's days.
--
Peter Eisentraut Sernanders väg 10:115
peter_e@gmx.net 75262 Uppsala
http://yi.org/peter-e/ Sweden
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [SQL] adding time to a datetime field ... how?
@ 1999-12-17 09:43 Margarit Nickolov <man@digsys.bg>
parent: Peter Eisentraut <peter_e@gmx.net>
0 siblings, 0 replies; 5+ messages in thread
From: Margarit Nickolov @ 1999-12-17 09:43 UTC (permalink / raw)
To: Peter Eisentraut <peter_e@gmx.net>; +Cc: The Hermit Hacker <scrappy@hub.org>; pgsql-sql
timespan type is `` time interval '@ <number> <units>' '' (try: db=>\dT),
and you can convert int4 to any timespan units this way:
textcat(int4_field, ' units_you_like')::timespan
units can be: secs, mins, hours, days, months, years
Margarit.
On Fri, 17 Dec 1999, Peter Eisentraut wrote:
> On 1999-12-15, Margarit Nickolov mentioned:
>
> > select start_time,start_time+acctsessiontime::timespan from log;
>
> Wow, that is really weird. I would consider it confusing behaviour at
> best if an explicit cast interprets an int as seconds whereas an implicit
> conversion thinks it's days.
>
>
> --
> Peter Eisentraut Sernanders väg 10:115
> peter_e@gmx.net 75262 Uppsala
> http://yi.org/peter-e/ Sweden
>
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~1999-12-17 09:43 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-15 13:31 adding time to a datetime field ... how? The Hermit Hacker <scrappy@hub.org>
1999-12-15 14:01 ` Margarit Nickolov <man@developer.digsys.bg>
1999-12-17 00:31 ` Peter Eisentraut <peter_e@gmx.net>
1999-12-17 09:43 ` Margarit Nickolov <man@digsys.bg>
1999-12-15 16:21 ` Vladimir Terziev <vlady@school.digsys.bg>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox