Re: Problem working with dates and times.

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема Re: Problem working with dates and times.
Дата
Msg-id E3230CE7-33DA-4976-9C86-94E0D55C814D@seespotcode.net
обсуждение исходный текст
Ответ на Problem working with dates and times.  ("Alejandro Michelin Salomon \( Adinet \)" <alejmsg@adinet.com.uy>)
Ответы RES: Problem working with dates and times.  ("Alejandro Michelin Salomon \( Adinet \)" <alejmsg@adinet.com.uy>)
Список pgsql-general
On Dec 5, 2006, at 8:13 , Alejandro Michelin Salomon (( Adinet )) wrote:

> This table has :
>
> Inicial date
> Inicial hour
> Duration
> Final Date
> Final time
>
> Final Date and Final time are calculate based in Inicial date,
> Inicial hour, Duration.

<snip />

> But i only need 2006-12-05 from the resulting timestamp.
>
> How to cut only the date from this timestamp?

# select cast('2006-12-04 20:00'::timestamp + interval '5 hours' as
date);
     date
------------
2006-12-05
(1 row)

That should do what you want.

I'd suggest changing your schema a little bit to remove the derived
columns.

inicial_timestamp timestamp with time zone
duration interval

I'd also recommend using timestamp with time zone, as it uniquely
identifies a global time.

Inicial date, inicial hour, final date, and final hour can be derived
from these two columns, e.g..

select cast('2006-12-04 20:00'::timestamptz + interval '5 hours' as
time);
    time
----------
01:00:00
(1 row)

This also saves you the need to check that final hour and final date
columns are correct compared to the inicial date, inicial hour, and
duration columns.

Hope this helps.

Michael Glaesemann
grzm seespotcode net



В списке pgsql-general по дате отправления:

Предыдущее
От: "Raymond O'Donnell"
Дата:
Сообщение: Re: Problem working with dates and times.
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: n00b RAID + wal hot standby question