Days, Hours, Min and Seconds Calculation [message #481686] |
Fri, 05 November 2010 05:20 |
myclassic
Messages: 136 Registered: December 2006 Location: Pakistan
|
Senior Member |
|
|
Dear All
I am able to run this query in Sql Prompt.
DEFINE Today = TO_DATE('03.12.2004:10:34:24','DD.MM.YYYY:HH24:MI:SS')
SELECT TO_CHAR(hiredate,'DD.MM.YYYY:HH24:MI:SS') "Hiredate",
TO_CHAR(&Today,'DD.MM.YYYY:HH24:MI:SS') "Today",
trunc(86400*(&Today-hiredate))-60*(trunc((86400*(&&Today-hiredate))/60)) "Sec",
trunc((86400*(&Today-hiredate))/60)-60*(trunc(((86400*(&&Today-hiredate))/60)/60)) "Min",
trunc(((86400*(&Today-hiredate))/60)/60)-24*(trunc((((86400*(&&Today-hiredate))/60)/60)/24)) "Hrs",
trunc((((86400*(&Today-hiredate))/60)/60)/24) "Days"
FROM emp;
It gives proper / desired results.
I want to use it on my Form, how can it be done?
any help is appreciated.
regards.
|
|
|
|
Re: Days, Hours, Min and Seconds Calculation [message #481690 is a reply to message #481688] |
Fri, 05 November 2010 05:32 |
myclassic
Messages: 136 Registered: December 2006 Location: Pakistan
|
Senior Member |
|
|
cookiemonster wrote on Fri, 05 November 2010 05:25What is stopping you using it in your form?
It's just a query, what's so difficult about including it?
DEFINE is stopping me.
this query will not run without DEFINE reserved.
where this DEFINE key word will be defined ???
|
|
|
Re: Days, Hours, Min and Seconds Calculation [message #481693 is a reply to message #481690] |
Fri, 05 November 2010 05:39 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
DEFINE is a sqlplus command for declaring variables. You know how to declare variables in forms don't you?
Also that query is way too complicated. This is a simpler version:
SQL> SELECT to_char(hiredate, 'DD-MON-YYYY HH24:MI:SS') hiredate,
2 to_char(today, 'DD-MON-YYYY HH24:MI:SS') today,
3 FLOOR(seconds/60/60/24) days,
4 MOD(FLOOR(seconds/60/60), 24) hours,
5 MOD(FLOOR(seconds/60), 60) mins,
6 MOD(seconds, 60) secs
7 FROM (SELECT SYSDATE hiredate,
8 TRUNC(SYSDATE -2) today,
9 (SYSDATE-TRUNC(SYSDATE -2)) * 60 * 60 * 24 seconds
10 FROM dual);
HIREDATE TODAY DAYS HOURS MINS SECS
-------------------- -------------------- ---------- ---------- ---------- ----------
05-NOV-2010 10:15:57 03-NOV-2010 00:00:00 2 10 15 57
SQL>
|
|
|