difference between dates [message #575537] |
Wed, 23 January 2013 22:53  |
 |
anilkln
Messages: 7 Registered: August 2012
|
Junior Member |
|
|
I am looking to subtract two columns and get the difference.Please suggest
select to_char('06-NOV-2012 20:00','DD-MON-YYYY HH24:MI') - to_char(systimestamp,'DD-MON-YY HH24:MI') from dual;
select to_char('06-NOV-2012 20:00','DD-MON-YYYY HH24:MI') - to_char(systimestamp,'DD-MON-YY HH24:MI') from dual
*
ERROR at line 1:
ORA-01722: invalid number
|
|
|
|
|
|
|
|
|
|
Re: difference between dates [message #575546 is a reply to message #575544] |
Wed, 23 January 2013 23:58   |
 |
sss111ind
Messages: 636 Registered: April 2012 Location: India
|
Senior Member |

|
|
WITH TEMP AS
(SELECT TO_DATE('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss') DATE1,
TO_DATE('02-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss') DATE2
FROM DUAL
)
SELECT date2-date1 days,(date2-date1)*24 hours,(date2-date1)*24*60 minutes,(date2-date1)*24*60*60 seconds
FROM temp;
WITH TEMP AS
(SELECT TO_DATE('01-01-2013 00:00:00','dd-mm-yyyy hh24:mi:ss') DATE1,
TO_DATE('02-01-2013 06:35:40','dd-mm-yyyy hh24:mi:ss') DATE2
FROM DUAL
)
SELECT round(DATE2-DATE1) DAYS,round((DATE2-DATE1)*24) HOURS,round((DATE2-DATE1)*24*60) MINUTES,round((DATE2-DATE1)*24*60*60) SECONDS
FROM temp;
Regards,
Nathan
|
|
|
Re: difference between dates [message #575553 is a reply to message #575543] |
Thu, 24 January 2013 01:35  |
 |
Michel Cadot
Messages: 68765 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:i have doubt here how is sysdate calculating the time here
It just asks the database server OS.
Every function is described in Database SQL Reference and the first line for SYSDATE is:
Quote:SYSDATE returns the current date and time set for the operating system on which the database resides
Regards
Michel
|
|
|