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.
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 .
{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.
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.
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):
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With