Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Substracting dates in Oracle

Substracting dates in Oracle

Scheduled Pinned Locked Moved Database
questiondatabaseoraclehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Diego F
    wrote on last edited by
    #1

    I have a problem substracting dates in Oracle. I tested the following: Create a new table with a date field Insert a register using sysdate Then a select (sysdate - dateField) doesn't return 0 as expected. In the SQL Developer it returns an empty field. How can I solve that? Sometimes, maybe depending on the time difference, it works and returns a value (really, I need (sysdate - datefield) * 24*60*60

    Regards, Diego F.

    S 1 Reply Last reply
    0
    • D Diego F

      I have a problem substracting dates in Oracle. I tested the following: Create a new table with a date field Insert a register using sysdate Then a select (sysdate - dateField) doesn't return 0 as expected. In the SQL Developer it returns an empty field. How can I solve that? Sometimes, maybe depending on the time difference, it works and returns a value (really, I need (sysdate - datefield) * 24*60*60

      Regards, Diego F.

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following: select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ), trunc( sysdate-created ) "Dy", trunc( mod( (sysdate-created)*24, 24 ) ) "Hr", trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi", trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec", to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ), sysdate-created "Tdy", (sysdate-created)*24 "Thr", (sysdate-created)*24*60 "Tmi", (sysdate-created)*24*60*60 "Tsec" from all_users where rownum < 50 /

      Regards, Satips.:rose:

      D 1 Reply Last reply
      0
      • S Sathesh Sakthivel

        To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following: select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ), trunc( sysdate-created ) "Dy", trunc( mod( (sysdate-created)*24, 24 ) ) "Hr", trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi", trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec", to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ), sysdate-created "Tdy", (sysdate-created)*24 "Thr", (sysdate-created)*24*60 "Tmi", (sysdate-created)*24*60*60 "Tsec" from all_users where rownum < 50 /

        Regards, Satips.:rose:

        D Offline
        D Offline
        Diego F
        wrote on last edited by
        #3

        Could you try that basic sample so I see what is the result? First create that table: CREATE TABLE TB_TEST ( ID NUMBER(2, 0) NOT NULL, DATEFIELD DATE , CONSTRAINT TB_TEST_PK PRIMARY KEY ( ID ) ) Now, I insert a register: insert into tb_test values (1, sysdate) commit; And then, the select query: select (sysdate-datefield) from tb_test where id=1 What is the result?

        Regards, Diego F.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups