Convert date & timestamp into seconds [message #604463] |
Tue, 31 December 2013 02:38 |
Nshan
Messages: 62 Registered: February 2009
|
Member |
|
|
Hi All,
Below is my requirement.
I have one date column say eta_column. Basically i need to enqueue the message into oracle queue with below delay time calculation,
If i am enqueueing at 10/14/2013 1:32:06 PM then my delay should also expire at trunc(eta_column) + timestamp should be the timestamp of enqueue time 1:32:06 PM
Ex : Enq_time = 10/14/2013 1:32:06 PM
Eta_column = 10/17/2013 1:00:00 AM
then Delay should expire @ 11/17/2013 1:32:00 PM not extactly the diff between Enq_time and Eta_column
Delay time should be pushed interms of seconds.
I can do a below calculation
(eta_column - trunc(sysdate))*24*60*60
But i am stuck at getting 1:32:06 PM value which should also be converted as seconds and added to previous value.
Could anyone please help me on this solution.
Thanks,
Nshan
|
|
|
|
Re: Convert date & timestamp into seconds [message #604466 is a reply to message #604463] |
Tue, 31 December 2013 03:08 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Well, I couldn't clearly understand your requirement. However, by what you said :
Quote:(eta_column - trunc(sysdate))*24*60*60
But i am stuck at getting 1:32:06 PM value which should also be converted as seconds and added to previous value.
I can suggest you not to use TRUNC. If you use TRUNC with DATE, see what happens -
SQL> select to_char(trunc(sysdate),'mm/dd/yyyy hh:mi:ss am') from dual;
TO_CHAR(TRUNC(SYSDATE),'MM/DD/
------------------------------
12/31/2013 12:00:00 am
So, the 'hh:mi:ss' part is defaulted to 12:00:00 am.
For correct calculation of seconds, you should leave it the way it is.
SQL> select to_char(sysdate,'mm/dd/yyyy hh:mi:ss am') from dual;
TO_CHAR(SYSDATE,'MM/DD/YYYYHH:
------------------------------
12/31/2013 01:03:07 am
The difference in two dates will be a number. You were right by multiplying 24*60*60 to get the difference in seconds. Just get rid of trunc.
SQL> WITH DATA AS(
2 SELECT to_date('10/17/2013 1:00:00 AM','mm/dd/yyyy hh:mi:ss am') eta_column from dual)
3 SELECT (SYSDATE - eta_column)*24*60*60 FROM DATA;
(SYSDATE-ETA_COLUMN)*24*60*60
-----------------------------
6480205
|
|
|
|
|