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
oracle
add a comment |
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
oracle
MySQL does not supportSYSDATE
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 useSYSTIMESTAMP
and also record the incoming timestamp.
– Tim Biegeleisen
Nov 9 at 9:17
add a comment |
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
oracle
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
oracle
edited Nov 9 at 9:12
asked Nov 9 at 9:07
cmb28
99215
99215
MySQL does not supportSYSDATE
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 useSYSTIMESTAMP
and also record the incoming timestamp.
– Tim Biegeleisen
Nov 9 at 9:17
add a comment |
MySQL does not supportSYSDATE
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 useSYSTIMESTAMP
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
add a comment |
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
add a comment |
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.
SYSDATE
does have a time component, you just can't directly access the time elements of a date withextract()
. (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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 9 at 9:37
George Joseph
1,14229
1,14229
add a comment |
add a comment |
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.
SYSDATE
does have a time component, you just can't directly access the time elements of a date withextract()
. (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
add a comment |
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.
SYSDATE
does have a time component, you just can't directly access the time elements of a date withextract()
. (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
add a comment |
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.
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.
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 withextract()
. (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
add a comment |
SYSDATE
does have a time component, you just can't directly access the time elements of a date withextract()
. (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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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