Re: Format string for ISO-8601 date and time

Поиск
Список
Период
Сортировка
От Daniel Verite
Тема Re: Format string for ISO-8601 date and time
Дата
Msg-id 14fcc880-db88-4194-b8bd-7385e8e15297@mm
обсуждение исходный текст
Ответ на Re: Format string for ISO-8601 date and time  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: Format string for ISO-8601 date and time  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-general
    Pavel Stehule wrote:

> > Is there a format string for to_char(timestamptz, text) that would
output a
> > timestamp in full ISO-8601 format? That is, something like
> > 1977-04-22T01:00:00-05:00
> >
> > I can't find a way to extract the offset against GMT from the docs
here:
> > http://www.postgresql.org/docs/8.3/static/functions-formatting.html
> >
> > If not, what would be the way to convert a timestamp to such a
string
> > regardless of the session's datestyle settings?
>
> try to look on function extract, there you can get timezone from any
> timestamp with time zone.

Thanks, I've come up with this expression, then:

 to_char(date, 'YYYY-MM-DD')
 || 'T'
 || to_char(date, 'HH24:MI:SS')
 || to_char(extract('timezone_hour' from date),'S00')
 ||':'
 || to_char(extract('timezone_minute' from date),'FM00')

This form is typically used in datetime fields in xml files, and
somehow I was expecting a pre-existing format for it, such as php5's
date("c") rather than the complex expression above :)

Best regards,

--
 Daniel

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

Предыдущее
От: Andrew Gould
Дата:
Сообщение: Off Topic: ICD-10 codes in a database table?
Следующее
От: Justin
Дата:
Сообщение: Re: foxpro, odbc, data types and unnecessary convertions