Custom datestyle for timestamps

Started by Daniel Veriteabout 17 years ago4 messagesgeneral
Jump to latest
#1Daniel Verite
daniel@manitou-mail.org

Hi,

SET DATESTYLE takes predefined keywords such as ISO or US as arguments,
but I can't find a way to specify a custom format string for
timestamps.

What I'd like to find is an equivalent to Oracle's
ALTER SESSION SET nls_date_format='DD/MM/YYYY HH24' for example,
where the format follows the sames rules than to_char and to_date.
This sets an implicit format for every subsequent text<->date
conversion.

Is there a way I could achieve that with postgres? A psql-only solution
would be good enough for me.

Thanks,

--
Daniel

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Daniel Verite (#1)
Re: Custom datestyle for timestamps

On Thursday 05 March 2009 00:19:02 Daniel Verite wrote:

SET DATESTYLE takes predefined keywords such as ISO or US as arguments,
but I can't find a way to specify a custom format string for
timestamps.

There is no support for that.

What I'd like to find is an equivalent to Oracle's
ALTER SESSION SET nls_date_format='DD/MM/YYYY HH24' for example,
where the format follows the sames rules than to_char and to_date.
This sets an implicit format for every subsequent text<->date
conversion.

... or that.

#3Daniel Verite
daniel@manitou-mail.org
In reply to: Peter Eisentraut (#2)
Re: Custom datestyle for timestamps

Peter Eisentraut wrote:

On Thursday 05 March 2009 00:19:02 Daniel Verite wrote:

SET DATESTYLE takes predefined keywords such as ISO or US as

arguments,

but I can't find a way to specify a custom format string for
timestamps.

There is no support for that.

What I'd like to find is an equivalent to Oracle's
ALTER SESSION SET nls_date_format='DD/MM/YYYY HH24' for example,
where the format follows the sames rules than to_char and to_date.
This sets an implicit format for every subsequent text<->date
conversion.

... or that.

I think it would valuable to have at least a default format that
doesn't include the sub-second precision, since it typically adds 7
characters that enlarge output columns in a way that is generally
useless to the human eyes. Do other users agree with that?

Best regards,
--
Daniel

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Daniel Verite (#3)
Re: Custom datestyle for timestamps

"Daniel Verite" <daniel@manitou-mail.org> writes:

I think it would valuable to have at least a default format that
doesn't include the sub-second precision, since it typically adds 7
characters that enlarge output columns in a way that is generally
useless to the human eyes. Do other users agree with that?

If you think it's useless, just store your timestamps in a timestamp(0)
column.

regards, tom lane