Skip site navigation (1) Skip section navigation (2)

Re: Looking for a way to get my time format.

From: Manuel Sugawara <masm(at)fciencias(dot)unam(dot)mx>
To: "Eric Naujock " <naujocke(at)abacusii(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Looking for a way to get my time format.
Date: 2001-06-04 16:22:50
Message-ID: m33d9g5i5h.fsf@dep1.fciencias.unam.mx (view raw or flat)
Thread:
Lists: pgsql-novice
"Eric Naujock " <naujocke(at)abacusii(dot)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(at)postgresql(dot)org)

In response to

pgsql-novice by date

Next:From: Thorsten MauchDate: 2001-06-04 20:10:06
Subject: HOWTO return a resultset form SP
Previous:From: Daniel A. MeloDate: 2001-06-04 15:30:22
Subject: problem with Timestamp

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group