Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle sql query for records with timestamp that falls between two timestamps

I have two timestamps in String format 2015-05-06T15:39:00 and 2015-04-06T15:39:00.

What is the sql query for Oracle that I can query all the records in the table that has timestamp that falls within this range.

like image 419
user1746050 Avatar asked May 06 '15 07:05

user1746050


People also ask

How can I find the difference between two timestamps in Oracle?

To calculate the difference between the timestamps in Oracle, simply subtract the start timestamp from the end timestamp (here: arrival - departure ). The resulting column will be in INTERVAL DAY TO SECOND . The first number you see is the number of whole days that passed from departure to arrival .

How can I find the difference between two timestamps in SQL?

{fn TIMESTAMPDIFF(interval,startDate,endDate)} returns the difference between the starting and ending timestamps (startDate minus endDate) for the specified date part interval (seconds, days, weeks, and so on). The function returns an INTEGER value representing the number of intervals between the two timestamps.

How do I get a dual TIMESTAMP?

SQL> SELECT SYSDATE FROM DUAL; In order to get the system date and time returned in a TIMESTAMP datatype, you can use the SYSTIMESTAMP function such as: SQL> SELECT SYSTIMESTAMP FROM DUAL; You can set the initialization parameter FIXED_DATE to return a constant value for what is returned from the SYSDATE function.

How do I query a TIMESTAMP in SQL?

To get a day of week from a timestamp, use the DAYOFWEEK() function: -- returns 1-7 (integer), where 1 is Sunday and 7 is Saturday SELECT dayofweek('2018-12-12'); -- returns the string day name like Monday, Tuesday, etc SELECT dayname(now()); To convert a timestamp to a unix timestamp (integer seconds):


1 Answers

And with alternative way you can use between

SELECT *
FROM tab1
WHERE timestamps BETWEEN TO_DATE ('2015-05-06T15:39:00', 'YYYY-MM-DD"T"HH24:MI:SS') AND TO_DATE('2015-04-06T15:39:00', 'YYYY-MM-DD"T"HH24:MI:SS');
like image 146
Moudiz Avatar answered Oct 29 '22 14:10

Moudiz