Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Calculating # of days,hours,mins

RE: Calculating # of days,hours,mins

From: Brian MacLean <bmaclean_at_homebid.com>
Date: Fri, 12 May 2000 13:49:46 -0700
Message-Id: <10495.105567@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------_=_NextPart_001_01BFBC53.9B2FA884

Content-Type: text/plain;

        charset="iso-8859-1"

SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160> create or replace function tm(v_date1 date, v_date2 date) return varchar2 is   2 v_rtn varchar2(20);
  3 begin
  4 v_rtn :=
  5 lpad(trunc(v_date1 - v_date2) ,2,'0') || ':' ||

  6  		        lpad(trunc((mod(v_date1 - v_date2,1) / (1/86400)) /
3600)	  ,2,'0') || ':' ||
  7  		    lpad(trunc(mod((mod(v_date1 - v_date2,1) / (1/86400)),
3600) / 60),2,'0') || ':' ||
  8  	    lpad(trunc(mod(mod((mod(v_date1 - v_date2,1) / (1/86400)),
3600), 60)),2,'0');
  9 return v_rtn;
 10 end;
 11 /

Function created.

SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160> select tm(sysdate, sysdate - 1.5) "DD:HH:MI:SS" from dual;

DD:HH:MI:SS




01:12:00:00

SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160>

Brian P. Mac Lean
Senior Oracle Database Administrator
OCPv8/Oracle Master
HomeBid.Com
8700 N. Gainey Center Drive
Scottsdale, AZ 85258

Tel:480.609.4624
Cel:602.617.6075
Fax:480.609.4646
Net:brian.maclean_at_homebid.com


-----Original Message-----

From: Kevin Martin [mailto:kevin.martin_at_catapultsystems.com] Sent: Friday, May 12, 2000 10:39 AM
To: Multiple recipients of list ORACLE-L Subject: Calculating # of days,hours,mins

Hi List.

I have a SQL question that should be fairly easy, but I haven't quite gotten it nailed down yet.

I am storing the in_date for a particular record. I need to calculate the number of days, hours, and minutes that have elapsed since the record was entered.

It should look something like this:

RECORD	AGE

--------------- --------
Item1 2 Days, 9 Hours, 32 Minutes

If any of you has done something similar, would you mind sharing your solution or steering me in the right direction?

Thanks.
-km

--

Author: Kevin Martin
  INET: kevin.martin_at_catapultsystems.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists

--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).

------_=_NextPart_001_01BFBC53.9B2FA884

Content-Type: text/html;

        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version = 5.5.2448.0">
<TITLE>RE: Calculating # of days,hours,mins</TITLE>
</HEAD>
<BODY>
<BR>

<P><FONT SIZE=3D1 =
FACE=3D"Terminal">SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160&gt; create = or replace function tm(v_date1 date, v_date2 date) return varchar2 = is</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 2&nbsp;&nbsp; v_rtn = varchar2(20);</FONT>

<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 3&nbsp; begin</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 4&nbsp;&nbsp;&nbsp; v_rtn =
:=3D</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 5&nbsp; &nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lpad(trunc(v_date1 - =
v_date2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; ,2,'0') || ':' ||</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 6&nbsp; &nbsp;&nbsp; = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lpad(trunc((mod(v_date1 - = v_date2,1) / (1/86400)) / 3600)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &nbsp; ,2,'0') || ':' ||</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 7&nbsp; &nbsp;&nbsp; = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = lpad(trunc(mod((mod(v_date1 - v_date2,1) / (1/86400)), 3600) / = 60),2,'0') || ':' ||</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 8&nbsp; &nbsp;&nbsp; = &nbsp;&nbsp;&nbsp; lpad(trunc(mod(mod((mod(v_date1 - v_date2,1) / = (1/86400)), 3600), 60)),2,'0');</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp; 9&nbsp;&nbsp; return = v_rtn;</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp;10&nbsp; end;</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal">&nbsp;11&nbsp; /</FONT>
</P>

<P><FONT SIZE=3D1 FACE=3D"Terminal">Function created.</FONT> </P>

<P><FONT SIZE=3D1 =
FACE=3D"Terminal">SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160&gt; select = tm(sysdate, sysdate - 1.5) &quot;DD:HH:MI:SS&quot; from dual;</FONT> </P>

<P><FONT SIZE=3D1 FACE=3D"Terminal">DD:HH:MI:SS</FONT> <BR><FONT SIZE=3D1 =

FACE=3D"Terminal">------------------------------------------------------=

--------------------------</FONT>

<BR><FONT SIZE=3D1 FACE=3D"Terminal">01:12:00:00</FONT> </P>

<P><FONT SIZE=3D1 =
FACE=3D"Terminal">SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160&gt;</FONT>

</P>
<BR>
<BR>
<BR>
<BR>
<BR>

<P><B><FONT COLOR=3D"#0000FF" FACE=3D"Comic Sans MS">Brian P. Mac = Lean</FONT></B>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans MS">Senior = Oracle Database Administrator</FONT>

<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans =
MS">OCPv8/Oracle Master</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans =
MS">HomeBid.Com</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans MS">8700 N. =
Gainey Center Drive</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans MS">Scottsdale, = AZ&nbsp; 85258</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans =
MS">Tel:480.609.4624</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans =
MS">Cel:602.617.6075</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans =
MS">Fax:480.609.4646</FONT>
<BR><FONT COLOR=3D"#808080" SIZE=3D1 FACE=3D"Comic Sans =
MS">Net:brian.maclean_at_homebid.com</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">-----Original Message-----</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">From: Kevin Martin [<A = HREF=3D"mailto:kevin.martin_at_catapultsystems.com">mailto:kevin.martin_at_cat= apultsystems.com</A>]</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Sent: Friday, May 12, 2000 10:39 = AM</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">To: Multiple recipients of list = ORACLE-L</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Subject: Calculating # of = days,hours,mins</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">Hi List.&nbsp; </FONT> </P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I have a SQL question that should be = fairly easy, but I haven't quite gotten</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">it nailed down yet.</FONT> </P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I am storing the in_date for a = particular record.&nbsp; I need to calculate the</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">number of days, hours, and minutes = that have elapsed since the record was</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">entered.</FONT> </P>

<P><FONT SIZE=3D2 FACE=3D"Arial">It should look something like = this:</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">RECORD&nbsp; AGE</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">--------------- --------</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Item1&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 Days, 9 Hours, 32 = Minutes</FONT>
</P>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Arial">If any of you has done something = similar, would you mind sharing your</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">solution or steering me in the right = direction?</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Thanks.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">-km</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">-- </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">Author: Kevin Martin</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">&nbsp; INET: = kevin.martin_at_catapultsystems.com</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Fat City Network = Services&nbsp;&nbsp;&nbsp; -- (858) 538-5051&nbsp; FAX: (858) = 538-5051</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">San Diego, = California&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Public Internet = access / Mailing Lists</FONT>
<BR><FONT SIZE=3D2 =

FACE=3D"Arial">---------------------------------------------------------=

-----------</FONT>

<BR><FONT SIZE=3D2 FACE=3D"Arial">To REMOVE yourself from this mailing = list, send an E-Mail message</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">to: ListGuru_at_fatcity.com (note EXACT = spelling of 'ListGuru') and in</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">the message BODY, include a line = containing: UNSUB ORACLE-L</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">(or the name of mailing list you want = Received on Fri May 12 2000 - 15:49:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US