Обсуждение: formating a select from a timestamp column

Поиск
Список
Период
Сортировка

formating a select from a timestamp column

От
stig erikson
Дата:
hi i have a column that is declared as:
datum timestamp DEFAULT ('now'::text)::timestamp(6) with time zone


then i do:
SELECT datum from table;
and get something like: 2005-11-13 00:00:00

i would like the output to be on the format: 2005-11-13
how can i change it?

i use postgresql 8.1

thanks
stig

Re: formating a select from a timestamp column

От
Andreas Kretschmer
Дата:
stig erikson <stigerikson_nospam_@yahoo.se> schrieb:

> hi i have a column that is declared as:
> datum timestamp DEFAULT ('now'::text)::timestamp(6) with time zone
>
>
> then i do:
> SELECT datum from table;
> and get something like: 2005-11-13 00:00:00
>
> i would like the output to be on the format: 2005-11-13
> how can i change it?

There are any ways. A simple way is to cast the timestamp to a date:

test=# select now();
              now
-------------------------------
 2005-11-19 09:05:06.750268+01
(1 Zeile)

test=# select now()::date;
    now
------------
 2005-11-19
(1 Zeile)



HTH, Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: formating a select from a timestamp column

От
Bruno Wolff III
Дата:
On Sun, Nov 13, 2005 at 11:30:33 +0100,
  stig erikson <stigerikson_nospam_@yahoo.se> wrote:
> hi i have a column that is declared as:
> datum timestamp DEFAULT ('now'::text)::timestamp(6) with time zone
>
>
> then i do:
> SELECT datum from table;
> and get something like: 2005-11-13 00:00:00
>
> i would like the output to be on the format: 2005-11-13
> how can i change it?

You could cast it to a date. If these times only represent dates, then you
should probably just store dates instead of timestamps.

>
> i use postgresql 8.1
>
> thanks
> stig
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

Re: formating a select from a timestamp column

От
Keith Worthington
Дата:
stig erikson wrote:
> hi i have a column that is declared as:
> datum timestamp DEFAULT ('now'::text)::timestamp(6) with time zone
>
>
> then i do:
> SELECT datum from table;
> and get something like: 2005-11-13 00:00:00
>
> i would like the output to be on the format: 2005-11-13
> how can i change it?
>
> i use postgresql 8.1
>
> thanks
> stig
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>
>

Stig,

How about just casting it to a date?

SELECT datum::date from table;

--
Kind Regards,
Keith