Обсуждение: Problem with showing time diff?
I have the following select: select to_char((Log_Fortrykk.SistePlate::time - OrdreNew.SistePlate::time)::interval,'HH24:MI') as diff from Log_Fortrykk I need the output to be HH:MM, e.g. 00:09... But my prb is when this diff is less than 0, it shows as 00:-9 and not -00:09 How can I fix this? Regards, BTJ -- ----------------------------------------------------------------------------------------------- Bjørn T Johansen btj@havleik.no ----------------------------------------------------------------------------------------------- Someone wrote: "I understand that if you play a Windows CD backwards you hear strange Satanic messages" To which someone replied: "It's even worse than that; play it forwards and it installs Windows" -----------------------------------------------------------------------------------------------
On Thu, Nov 11, 2004 at 11:55:33AM +0100, Bj�rn T Johansen wrote:
>
> select to_char((Log_Fortrykk.SistePlate::time -
> OrdreNew.SistePlate::time)::interval,'HH24:MI') as diff from Log_Fortrykk
>
> I need the output to be HH:MM, e.g. 00:09... But my prb is when this diff
> is less than 0, it shows as 00:-9 and not -00:09
The documentation deprecates to_char(interval, text) and the Release
Notes for 8.0 say that 8.1 will remove it.
You might be able to use substring():
SELECT substring('-00:09:10'::interval from '(.*):[0-9][0-9]$');
substring
-----------
-00:09
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/