Get time difference in minutes between current time and the time that data was inserted to DB









up vote
1
down vote

favorite












I have a system making third party API request to another server. But i want to make sure the user doesn't request again within the next 15 minutes of the first request. So I check time difference in below method which is not working correctly,



ROUND(sysdate - d.CREATE_DATE,2) as PASSED_TIME


Here d.CREATE_DATE is also saved by using SYSDATE keyword when the first request is sent. I get a number out put but it doesn't seem to be right.
So I want to know how can i take time difference in minutes










share|improve this question























  • MySQL does not support SYSDATE AFAIK. What is your actual database?
    – Tim Biegeleisen
    Nov 9 at 9:10










  • @TimBiegeleisen it supports. Ref: dev.mysql.com/doc/refman/8.0/en/…
    – Madhur Bhaiya
    Nov 9 at 9:11










  • @TimBiegeleisen sorry. Oracle database
    – cmb28
    Nov 9 at 9:13










  • You need to use SYSTIMESTAMP and also record the incoming timestamp.
    – Tim Biegeleisen
    Nov 9 at 9:17














up vote
1
down vote

favorite












I have a system making third party API request to another server. But i want to make sure the user doesn't request again within the next 15 minutes of the first request. So I check time difference in below method which is not working correctly,



ROUND(sysdate - d.CREATE_DATE,2) as PASSED_TIME


Here d.CREATE_DATE is also saved by using SYSDATE keyword when the first request is sent. I get a number out put but it doesn't seem to be right.
So I want to know how can i take time difference in minutes










share|improve this question























  • MySQL does not support SYSDATE AFAIK. What is your actual database?
    – Tim Biegeleisen
    Nov 9 at 9:10










  • @TimBiegeleisen it supports. Ref: dev.mysql.com/doc/refman/8.0/en/…
    – Madhur Bhaiya
    Nov 9 at 9:11










  • @TimBiegeleisen sorry. Oracle database
    – cmb28
    Nov 9 at 9:13










  • You need to use SYSTIMESTAMP and also record the incoming timestamp.
    – Tim Biegeleisen
    Nov 9 at 9:17












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a system making third party API request to another server. But i want to make sure the user doesn't request again within the next 15 minutes of the first request. So I check time difference in below method which is not working correctly,



ROUND(sysdate - d.CREATE_DATE,2) as PASSED_TIME


Here d.CREATE_DATE is also saved by using SYSDATE keyword when the first request is sent. I get a number out put but it doesn't seem to be right.
So I want to know how can i take time difference in minutes










share|improve this question















I have a system making third party API request to another server. But i want to make sure the user doesn't request again within the next 15 minutes of the first request. So I check time difference in below method which is not working correctly,



ROUND(sysdate - d.CREATE_DATE,2) as PASSED_TIME


Here d.CREATE_DATE is also saved by using SYSDATE keyword when the first request is sent. I get a number out put but it doesn't seem to be right.
So I want to know how can i take time difference in minutes







oracle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 9:12

























asked Nov 9 at 9:07









cmb28

99215




99215











  • MySQL does not support SYSDATE AFAIK. What is your actual database?
    – Tim Biegeleisen
    Nov 9 at 9:10










  • @TimBiegeleisen it supports. Ref: dev.mysql.com/doc/refman/8.0/en/…
    – Madhur Bhaiya
    Nov 9 at 9:11










  • @TimBiegeleisen sorry. Oracle database
    – cmb28
    Nov 9 at 9:13










  • You need to use SYSTIMESTAMP and also record the incoming timestamp.
    – Tim Biegeleisen
    Nov 9 at 9:17
















  • MySQL does not support SYSDATE AFAIK. What is your actual database?
    – Tim Biegeleisen
    Nov 9 at 9:10










  • @TimBiegeleisen it supports. Ref: dev.mysql.com/doc/refman/8.0/en/…
    – Madhur Bhaiya
    Nov 9 at 9:11










  • @TimBiegeleisen sorry. Oracle database
    – cmb28
    Nov 9 at 9:13










  • You need to use SYSTIMESTAMP and also record the incoming timestamp.
    – Tim Biegeleisen
    Nov 9 at 9:17















MySQL does not support SYSDATE AFAIK. What is your actual database?
– Tim Biegeleisen
Nov 9 at 9:10




MySQL does not support SYSDATE AFAIK. What is your actual database?
– Tim Biegeleisen
Nov 9 at 9:10












@TimBiegeleisen it supports. Ref: dev.mysql.com/doc/refman/8.0/en/…
– Madhur Bhaiya
Nov 9 at 9:11




@TimBiegeleisen it supports. Ref: dev.mysql.com/doc/refman/8.0/en/…
– Madhur Bhaiya
Nov 9 at 9:11












@TimBiegeleisen sorry. Oracle database
– cmb28
Nov 9 at 9:13




@TimBiegeleisen sorry. Oracle database
– cmb28
Nov 9 at 9:13












You need to use SYSTIMESTAMP and also record the incoming timestamp.
– Tim Biegeleisen
Nov 9 at 9:17




You need to use SYSTIMESTAMP and also record the incoming timestamp.
– Tim Biegeleisen
Nov 9 at 9:17












2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










For oracle, it is enough to just subtract the dates if the field "CREATE_DATE" is "date" datatype and multiply by 24*60 to get the difference in minutes.
Eg:



select to_char(sysdate-15/24/60,'dd-mon-yyyy hh24:mi:ss') as first_request /*15 minutes back*/
,to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') as current_request
,(sysdate - sysdate +15/24/60)*24*60 as diff_in_minutes
from dual





share|improve this answer



























    up vote
    1
    down vote













    One option would be recording and comparing to SYSTIMESTAMP:



    SELECT
    EXTRACT (day FROM ts) * 24*60 +
    EXTRACT (hour FROM ts) * 60 +
    EXTRACT (minute FROM ts) AS PASSED_TIME
    FROM
    (
    SELECT SYSTIMESTAMP - CREATE_TS ts
    FROM yourTable
    ) t;


    This answer assumes that the CREATE_TS column stores the incoming timestamps, using SYSTIMESTAMP as the incoming value.






    share|improve this answer






















    • SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
      – Alex Poole
      Nov 9 at 9:48






    • 1




      @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
      – Tim Biegeleisen
      Nov 9 at 10:31










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222699%2fget-time-difference-in-minutes-between-current-time-and-the-time-that-data-was-i%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    For oracle, it is enough to just subtract the dates if the field "CREATE_DATE" is "date" datatype and multiply by 24*60 to get the difference in minutes.
    Eg:



    select to_char(sysdate-15/24/60,'dd-mon-yyyy hh24:mi:ss') as first_request /*15 minutes back*/
    ,to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') as current_request
    ,(sysdate - sysdate +15/24/60)*24*60 as diff_in_minutes
    from dual





    share|improve this answer
























      up vote
      2
      down vote



      accepted










      For oracle, it is enough to just subtract the dates if the field "CREATE_DATE" is "date" datatype and multiply by 24*60 to get the difference in minutes.
      Eg:



      select to_char(sysdate-15/24/60,'dd-mon-yyyy hh24:mi:ss') as first_request /*15 minutes back*/
      ,to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') as current_request
      ,(sysdate - sysdate +15/24/60)*24*60 as diff_in_minutes
      from dual





      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        For oracle, it is enough to just subtract the dates if the field "CREATE_DATE" is "date" datatype and multiply by 24*60 to get the difference in minutes.
        Eg:



        select to_char(sysdate-15/24/60,'dd-mon-yyyy hh24:mi:ss') as first_request /*15 minutes back*/
        ,to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') as current_request
        ,(sysdate - sysdate +15/24/60)*24*60 as diff_in_minutes
        from dual





        share|improve this answer












        For oracle, it is enough to just subtract the dates if the field "CREATE_DATE" is "date" datatype and multiply by 24*60 to get the difference in minutes.
        Eg:



        select to_char(sysdate-15/24/60,'dd-mon-yyyy hh24:mi:ss') as first_request /*15 minutes back*/
        ,to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') as current_request
        ,(sysdate - sysdate +15/24/60)*24*60 as diff_in_minutes
        from dual






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 9:37









        George Joseph

        1,14229




        1,14229






















            up vote
            1
            down vote













            One option would be recording and comparing to SYSTIMESTAMP:



            SELECT
            EXTRACT (day FROM ts) * 24*60 +
            EXTRACT (hour FROM ts) * 60 +
            EXTRACT (minute FROM ts) AS PASSED_TIME
            FROM
            (
            SELECT SYSTIMESTAMP - CREATE_TS ts
            FROM yourTable
            ) t;


            This answer assumes that the CREATE_TS column stores the incoming timestamps, using SYSTIMESTAMP as the incoming value.






            share|improve this answer






















            • SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
              – Alex Poole
              Nov 9 at 9:48






            • 1




              @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
              – Tim Biegeleisen
              Nov 9 at 10:31














            up vote
            1
            down vote













            One option would be recording and comparing to SYSTIMESTAMP:



            SELECT
            EXTRACT (day FROM ts) * 24*60 +
            EXTRACT (hour FROM ts) * 60 +
            EXTRACT (minute FROM ts) AS PASSED_TIME
            FROM
            (
            SELECT SYSTIMESTAMP - CREATE_TS ts
            FROM yourTable
            ) t;


            This answer assumes that the CREATE_TS column stores the incoming timestamps, using SYSTIMESTAMP as the incoming value.






            share|improve this answer






















            • SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
              – Alex Poole
              Nov 9 at 9:48






            • 1




              @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
              – Tim Biegeleisen
              Nov 9 at 10:31












            up vote
            1
            down vote










            up vote
            1
            down vote









            One option would be recording and comparing to SYSTIMESTAMP:



            SELECT
            EXTRACT (day FROM ts) * 24*60 +
            EXTRACT (hour FROM ts) * 60 +
            EXTRACT (minute FROM ts) AS PASSED_TIME
            FROM
            (
            SELECT SYSTIMESTAMP - CREATE_TS ts
            FROM yourTable
            ) t;


            This answer assumes that the CREATE_TS column stores the incoming timestamps, using SYSTIMESTAMP as the incoming value.






            share|improve this answer














            One option would be recording and comparing to SYSTIMESTAMP:



            SELECT
            EXTRACT (day FROM ts) * 24*60 +
            EXTRACT (hour FROM ts) * 60 +
            EXTRACT (minute FROM ts) AS PASSED_TIME
            FROM
            (
            SELECT SYSTIMESTAMP - CREATE_TS ts
            FROM yourTable
            ) t;


            This answer assumes that the CREATE_TS column stores the incoming timestamps, using SYSTIMESTAMP as the incoming value.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 9 at 10:31

























            answered Nov 9 at 9:20









            Tim Biegeleisen

            212k1384132




            212k1384132











            • SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
              – Alex Poole
              Nov 9 at 9:48






            • 1




              @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
              – Tim Biegeleisen
              Nov 9 at 10:31
















            • SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
              – Alex Poole
              Nov 9 at 9:48






            • 1




              @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
              – Tim Biegeleisen
              Nov 9 at 10:31















            SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
            – Alex Poole
            Nov 9 at 9:48




            SYSDATE does have a time component, you just can't directly access the time elements of a date with extract(). (I'm 100% sure you know that really, of course *8-)
            – Alex Poole
            Nov 9 at 9:48




            1




            1




            @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
            – Tim Biegeleisen
            Nov 9 at 10:31




            @AlexPoole Oracle is to me like a complex maze of APIs. It is also one of the most powerful databases out there.
            – Tim Biegeleisen
            Nov 9 at 10:31

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222699%2fget-time-difference-in-minutes-between-current-time-and-the-time-that-data-was-i%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)