Thread: Looking for a way to get my time format.
I am looking for a way to get my time format to display in the format of hh:mm AM/PM instead to the default 24 hour timeformat. Does anybody have any suggestions for how to do this?
What you need is the to_char() function. The documentation for this function can be found here: http://www.postgresql.org/idocs/index.php?functions-formatting.html Here's an example of how you would use this function. processdata=> select to_char(now(), 'YYYY-DD-MM HH:MM:SS PM') processdata-> ; to_char ------------------------ 2001-04-06 08:06:32 AM (1 row) Notice how the format string has PM in it but the time returned is AM, that spooked me at first, but it seems to work as one would hope. Jason --- Eric Naujock <naujocke@abacusii.com> wrote: > I am looking for a way to get my time format to > display in the format of hh:mm AM/PM instead to the > default 24 hour time format. Does anybody have any > suggestions for how to do this? > > > ---------------------------(end of > broadcast)--------------------------- > TIP 2: you can get off all lists at once with the > unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/
"Eric Naujock " <naujocke@abacusii.com> writes: > I am looking for a way to get my time format to display in the > format of hh:mm AM/PM instead to the default 24 hour time > format. Does anybody have any suggestions for how to do this? There's no function to_char for time :-(; try with your own function. Something like create function time2str(time) returns text as ' declare var_time alias for $1; var_hrs int; var_mins int; var_mod text; begin var_hrs := extract(hours from var_time); var_mins := extract(minutes from var_time); if var_hrs >= 12 then var_mod := ''PM''; if var_hrs > 12 then var_hrs := var_hrs - 12; end if; else var_mod := ''AM''; end if; return to_char(var_hrs,''fm00'') || '':'' || to_char(var_mins,''fm00'') || var_mod; end; ' language 'plpgsql'; regression=# select time2str('7:00:00'::time); time2str ---------- 07:00AM (1 row) regression=# hth, Manuel. > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)