Re: [SQL] datetime function
От | José Soares |
---|---|
Тема | Re: [SQL] datetime function |
Дата | |
Msg-id | 3757E80E.7A92835F@sferacarta.com обсуждение исходный текст |
Ответ на | datetime function ("Pham, Thinh" <tpham@mail.priority.net>) |
Список | pgsql-sql |
<tt>In SQL/92:</tt><tt></tt><p><tt>prova=> select CURRENT_TIME as now, time '18:50:00' - current_time as diff;</tt><br/><tt>now |diff</tt><br /><tt>--------+--------</tt><br /><tt>18:47:48|00:02:12</tt><br /><tt>(1 row)</tt><br/><tt></tt> <tt></tt><p><tt>To have this in PostgreSQL create a PL/pgSQL function like:</tt><tt></tt><p><tt>createfunction time_mi_time(time,time) returns timespan as</tt><br /><tt>'</tt><br /><tt>declare</tt><br/><tt> i1 interval;</tt><br /><tt> i2 interval;</tt><br /><tt>begin</tt><br /><tt> i1:= $1;</tt><br /><tt> i2:= $2;</tt><br /><tt> i1:=i1 - i2;</tt><br /><tt> return i1;</tt><br/><tt>end;</tt><br /><tt>' language 'plpgsql';</tt><tt></tt><p><tt>create operator - (</tt><br /><tt> leftarg=time,</tt><br/><tt> rightarg=time,</tt><br /><tt> procedure=time_mi_time,</tt><br /><tt> commutator='-',</tt><br/><tt> negator='+',</tt><br /><tt> restrict=eqsel,</tt><br /><tt> join=eqjoinsel</tt><br/><tt> );</tt><br /><tt></tt> <p>"Pham, Thinh" ha scritto: <blockquote type="CITE">Is thereany sql92 functions (not really essential) that calculates the <br />timespan between 2 separate points in time? Forexample, i want to calculate <br />the total minutes between 2:30pm and 3:30pm. There's a function like this in <br />microsoftsql but i can't find it in postgres. Below is how it works in ms: <p>DATEDIFF(minute, '14:30', '15:30') <p>I lookedat the "timespan" function but it's not the same one that i need. <br />Thanks, <br />Thinh</blockquote><blockquotetype="CITE">--</blockquote> ______________________________________________________________<br />PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc2.7.2.3 <br />^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <br />Jose' <br />
В списке pgsql-sql по дате отправления: