Обсуждение: adding time to a datetime field ... how?
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
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
>
>
> ************
>
>
Try select start_time, abstime_datetime(start_time::abstime + acctsessiontime) from log; Regards! Vladimir
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
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 > > >