Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Calculating # of days,hours,mins
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');
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
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 Liststo: 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).
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
------_=_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">
<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> create =
or replace function tm(v_date1 date, v_date2 date) return varchar2 =
is</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal"> 2 v_rtn =
varchar2(20);</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal"> 3 begin</FONT> <BR><FONT SIZE=3D1 FACE=3D"Terminal"> 4 v_rtn = :=3D</FONT> <BR><FONT SIZE=3D1 FACE=3D"Terminal"> 5 = = = lpad(trunc(v_date1 - =
v_date2) &nbs= p; &nbs= p; ,2,'0') || ':' ||</FONT><BR><FONT SIZE=3D1 FACE=3D"Terminal"> 6 = = lpad(trunc((mod(v_date1 - = v_date2,1) / (1/86400)) / 3600) = ,2,'0') || ':' ||</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Terminal"> 10 end;</FONT> <BR><FONT SIZE=3D1 FACE=3D"Terminal"> 11 /</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> select =
tm(sysdate, sysdate - 1.5) "DD:HH:MI:SS" from dual;</FONT>
</P>
<P><FONT SIZE=3D1 FACE=3D"Terminal">DD:HH:MI:SS</FONT> <BR><FONT SIZE=3D1 =
FACE=3D"Terminal">------------------------------------------------------=
--------------------------</FONT>
<P><FONT SIZE=3D1 =
FACE=3D"Terminal">SQL_at_dev1:HBDEV1:8.1.5:OPS$ORACLE:38,9160></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">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. </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. 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 AGE</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">--------------- --------</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">Item1 = 2 Days, 9 Hours, 32 = Minutes</FONT>
<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"> INET: = kevin.martin_at_catapultsystems.com</FONT>
<P><FONT SIZE=3D2 FACE=3D"Arial">Fat City Network =
Services -- (858) 538-5051 FAX: (858) =
538-5051</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">San Diego, =
California -- Public Internet =
access / Mailing Lists</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial">---------------------------------------------------------=
![]() |
![]() |