tags:

views:

18

answers:

1

How can I output postgresql dates with ISO 8601-compliant timezones?

e.g. I have the value

2006-11-10 07:35:30+01

and I need it in this format:

2006-11-10T07:35+01

I could do that easily enough with string manipulation, but the standard date formatting functions for

to_char(<my date>, 'YYYY-MM-DDThh:mmTD')

would give me this:

2006-11-10T07:11CET

instead of this:

2006-11-10T07:11+02

Is there a way to get the timzone as an offset instead of as an abbreviation?

A: 

Using string manipulation, maybe? Like:

regexp_replace(current_date || 'T' || current_time, E':[^:]*?\\+', E'+');

or

replace( regexp_replace(now()::text, E':[^:]*?\\+', E'+'), ' ', 'T' );

Not elegant, but it gets the job done (tested with 8.3)

Dan Andreatta
"get the job done" = good enough for me! Thank you.
adwk