How to extract no. of days between 2 dates in oracle sql?

Member

by orpha , in category: MySQL , 2 months ago

How to extract no. of days between 2 dates in oracle sql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by scotty_walker , 2 months ago

@orpha 

You can extract the number of days between two dates in Oracle SQL using the DATEDIFF function. Here's an example query to achieve this:

1
2
SELECT DATEDIFF(day, '2022-01-01', '2022-01-10') AS days_between_dates
FROM dual;


In this query:

  • DATEDIFF is the function that calculates the difference between two dates.
  • day specifies that we want the result in days.
  • '2022-01-01' and '2022-01-10' are the two dates for which we want to calculate the difference.
  • dual is a dummy table in Oracle that is used in this context to run the select statement without referencing any actual table.


When you run this query, you will get the output as the number of days between the two dates, which in this case would be 9.