oracle datediff in months. DATEDIFF(interval, date1, date2) Parameter Values. oracle datediff in months

 
 DATEDIFF(interval, date1, date2) Parameter Valuesoracle datediff in months  I don't think this is really important to your question

In certain cases, such as string-based comparisons or when a result depends on a different timestamp format than is set in the session parameters, we recommend explicitly converting. date_open END. 0. 6,487 5 25 37. SELECT DATEDIFF (YY, DateOfBirth, GETDATE ()) - CASE WHEN RIGHT (CONVERT (VARCHAR (6), GETDATE (), 12), 4) >= RIGHT (CONVERT (VARCHAR (6), DateOfBirth, 12), 4) THEN 0 ELSE 1 END AS AGE. February 28 and March 31) can lead to unintuitive behavior; specifically, increasing the first date in the pair does not always increase the output value. I am looking for a way to implement the SQLServer-function datediff in PostgreSQL. (Oct 2006 - June 2005 = 16) DP_WEEK returns the distance between the weeks capturing the input. Note that it is subtracting the second from the first, so you must have them in this order. As shown clearly in the result, because 2016 is the leap year, the difference in days between two dates is 2×365 + 366 = 1096. SQL Server has a nice function called DateDiff which takes a date part, startdate and enddate. 4 Answers. getMonth (); return m2 - m1 + 1; } EDIT: Since Java 8, there is a more. Order your results by the number of years employed. created_date - adhh. using the following expression. I usually used MySQL or sometimes Oracle but now I have to switch to Teradata. Fractions are allowed; you can add 2. I hope you will like the SQL Date Functions Examples article. I tried this: TO_DATE (sysdate) - TO_DATE (thedate, 'YYYY-MM-DD') < 5. For example, with some sample dates: select months_between (date '2015-03-19', date '2012-01-06') as month_diff from dual; MONTH_DIFF ---------- 38. Fractions are allowed; you can add 2. So, for example: WHERE date2 - date1 BETWEEN 60 AND 90. Modified 2 years, 6 months ago. DAYS function. Modified 8 years, 2 months ago. Columns c ) n cross join (select cast ('2001-01-01' as date) firstdate) const. 9. The format argument is a string format that specifies which unit the date should be rounded to. Hi tom, I want day, month, minute and years difference everyting in seconds. Sum (r => EF. Oracle's MONTHS_BETWEEN on the other hand tries to calculate an exact difference in months' fractions: select months_between(date '2021-02-01', date '2021-01-31') from dual; => 0. But your query is giving the last date of previous month. It operates according to the rules of the Gregorian calendar. That link is not for the Oracle database, it's for JavaDB (Derby). 99. Difference of two dates in months. Table 9. If the dates are really timestamps, then this is easy - subtract them and the result is a day to second interval. Currently I am only returning 1. 4193548. select *, cast ( (cast (begin_date as date) - cast (end_date as date) YEAR) as decimal (3,2)) AS year_diff from x. The dates do not have to be in the same format in the extract file, but the format of each must be supported. I am adding filter to OTBI report and want system to take first and last date of current month automatically. For example, the function considers each of the following pairs of dates/timestamps to be exactly 1. 0. The add_days variable can be negative. See Date and Time Data Types and Functions (Transact-SQL) for an overview of all Transact. The difference between two dates (in oracle's usual database product) is in days (which can have fractional parts). This post has been answered by BluShadow on Nov 18 2010. A numeric value is returned. Date Interval Calculation: The number of specified date parts between two provided dates is found using the DATEDIFF () method. In my opinion the date diff is kind of subjective, especially on days. EMPLOYEES; This is some old sample. Arguments. numeric-expression. 2903225806. This example returns the date of the next Sunday after January 1, 2000: SELECT NEXT_DAY ( DATE '2000-01-01', 'SUNDAY' ) FROM dual; Code language: SQL (Structured Query Language) (sql) It returns the following output: 02-JAN-00 Code language: SQL (Structured Query Language) (sql) Oracle doesn't have a DATEDIFF() function. Modified 11 years, 3 months ago. Get Value for Last Month. ops$tkyte@8i> select months_between ( end_date, start_date ), 2 trunc ( months_between ( end_date, start_date ) /12 ) Years, 3 mod (. Finding the seconds difference can be done as follows: SELECT (mod_date_time - create_date_time) * 24 * 60 * 60 as "seconds_diff" FROM t1. 208333, so the value is correct! So now that we know how subtracting dates. Conversion among time units is also allowed; you can add, subtract, or compare dates by using days and state. You have to cast it first, using to_date: select to_date ('2000-01-01', 'yyyy-MM-dd') - to_date ('2000-01-02', 'yyyy-MM-dd'). Only 10+ years later - here's a db<>fiddle which demonstrates the difference between subtracting a date from a date (e. 0. The days are in two different, adjacent months, so the answer is 1 month difference. We would like to show you a description here but the site won’t allow us. Apart from using Joda time which seems to be the the favorite suggestion I'd offer the following snippet: public static final int getMonthsDifference (Date date1, Date date2) { int m1 = date1. You may: count the number of 24h elapsed time: day+1 - day = 1 day = 24h. Share. Here is some T-SQL that gives you the number of years, months, and days since the day specified in @date. StartDate, SYSDATE) you would use: MONTHS_BETWEEN(pr. You want to pass TIMESTAMP arguments to the function and when you add years you also need to ensure that you propagate the fractional component of the timestamp (since ADD_MONTHS returns a DATE data-type without fractional seconds): Unfortunately, Oracle SQL doesn't allow the DATEDIFF function. I have used the below query to find the number of weeks between two dates: select count (week_id) from fw where week_begin_date >= '2015-01-01' and week_end_date <= '2015-12-31'; Expected result should be 53 but the actual result is 51. subtracting date literals as pure dates without conversion. Should I change (edit) the title or delete and re-post the question properly? This is what I'm addressing. SQL Retrieve the records of previous month. Try SELECT SYSTIMESTAMP + INTERVAL '5' MINUTE, SYSTIMESTAMP + 5 / 24 / 60 to convince yourself. To answer your question to find all records that occurred last month. January 30, 2022 5:11 PM / SQL. COMPUTE days2 = DATEDIFF(date2,date1,"days"). Modified 7 years, 2 months ago. ) The dates and their formats are separated by a comma (,) and are defined in the Data field of the. g. If you can join an external Oracle table to an OutSystems table, that means that both tables are on the same database, so you are using Oracle for OutSystems as well. 1. 3 Answers. however using the below sql statement im getting. The syntax for the DATEDIFF function is as follows:. proc sql noprint; create table daystoOverdue_list as select distinct business_object_rk , DateDiff (DAY, value_dt, Today ()) as value_dt from case_DataTable_d as tbl where tbl. Modified 9 years ago. last_day (feb) to last_day (mar) is also commonly accepted as a "month". select Dateadd(Month, -12, '2015-08-17') What I want is to get the last 12 months but ending at 2014-08-01 (in the above case) instead of any where in the middle of the month. If you want to confirm, simply run this. We have accounting date between parameter in report. DateDiff(“m”, Fields! starting date. datediff() is not giving tHe result as I am working in Oracle. Share. I have to get the date from the system and calculate the date difference in days. hourEnd)) AS Expr1 FROM a INNER JOIN tp ON a. For instance, select datediff (day,'1 Jan 2000' ,'18 April 2014') / 365. Answer: You can use the months_between function and convert it easily yo years between and decades between two dates: months_between/12 = years between. Hi, Everyone, I am trying to find out the difference in days between two dates and the query i am passing is SELECT TO_char(sysdate, 'dd/mm/yyyy')-TO_char('15/11/2011', 'dd/mm/yyyy') DAYS FROM DUAL. Current Date/Time. The MONTHS_BETWEEN () function is used to get the number of months between dates (date1, date2). EXE. It can be used to do date math as well. (floor ( (Base_DateDiff + 1 + Start_WeekDay) / 7)) counts the number of saturdays. Improve this question. Follow edited Apr 7, 2020 at. DATEDIFF(Day, MIN(joindate), MAX(joindate)) AS DateDifferen. PROJECTED_COMPLETION,. This function is used to find the difference between two specified values of date. * 12 + (Extract(Month From CDate(EndDate)) - Extract(Month. Adds days, months, and years to the date and returns the result. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the. When you subtract two dates in Oracle, you get the number of days between the two values. And you can use intervals, but using month intervals for. hourBegin, a. I have a creation date column in the table. DateDiff is not a function that exists in Oracle. Current Month. Can be one of the following values:1 Answer. SELECT DATE '0016-08-03' - DATE '2016-07-08' FROM dual;-- -730461. The system always returns a positive number regardless of which date. DATE_DIFF = 1. 2 Answers. NET and i have faced several problems that i could fix but i couldn't fix the following: I have a stored procedure that takes date in parameters The stored procedures calls to_date with the format : MM/DD/YY HH:MI:SS AM The. That is, this function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified start date and end date. ) Startdate = 2014-04-03 enddate = 2013-04-03 Result should be 12 as OP said. But since it's a finite set, you can just get. Viewed 4k times 1 I have a table with below structure. You can use this methodology to determine the first day of 3 months ago, and the last day of the previous month: select DATEADD (MONTH, DATEDIFF (MONTH, 0, GETDATE ())-3, 0) --First day of 3 months ago select DATEADD (MONTH, DATEDIFF (MONTH, -1, GETDATE ())-1, -1) --Last Day of previous month. For a baby born 28-Feb-17, properly calculated they turn 1 years old on 28-Feb-18 - their next birthday. I have a creation date column in the table. As you can see the EOMONTH function takes into account leap year. Oracle GoldenGate add trandata errors. SELECT CASE WHEN DATEDIFF (d,'2013-09-01', '2013-11-15')>30 THEN DATEDIFF (d,'2013-09-01', '2013-11-15')/30. #1633022. Improve this answer. idUsage Notes¶. DP_MONTH returns the distance between the months capturing the input dates. lastModified and w. date or field. DATEDIFF (datepart, startdate, enddate) which can return the difference in years, months, days etc. Goal. SS: 差異を秒数で計算します。. Few examples of DATEDIFF: DATEDIFF - Example 1 Here, in this example, datepart is "day": SELECT DATEDIFF(day,'2016-06-05','2016-08-05') AS DiffDate. DiffMonths ("05/01/95",. 18. Then you use the TO_DATE () function to. In addition, with DATEDIFF () the column is an argument to the function. この番号を取得するには、次のいずれかの関数を使用: Today ()、TodateEx ()、GetFirstDate ()、GetLastDate ()、DateRoll ()。. Actually I have created a function for this but that quite complex . , a year, a quarter, a month, a week that you want to compare between the start_date and end_date. (Oct 2006 - June 2005 = 16) DP_WEEK returns the distance between the weeks capturing the input dates. As you can see it means that year should be -1, and month 0. Feb-N to Mar-N is commonly accepted as a "month". Oracle has a months_between function: AND MONTHS_BETWEEN (sysdate, s. 25. I apologize for the misinformation. The months_between function returns the elapsed months going from the second date to the first. id (SELECT SUM(DATEDIFF(HOUR, a. 9. SELECT DATEDIFF(day, '2018-03-13', GETDATE()) AS "Difference in days"; On that basis, let me explain the three arguments required in the DATEDIFF function syntax. Example. DATE () Extract the date part of a date or datetime expression. I am trying to create a new column that will show the age of the person on the date that they took up the membership. How to calculate days difference between two dates without leap year (365 days each year)? Thank you so much! I am new to Oracle Community Support, and I assumed that if I posted question in Oracle under SQL and PL/SQL, people would understand what I need. You may need to change date format to match the a given date format and verify that 31 day months work for your specific scenarios. AVERAGES CTE shows how to apply AVG function to. 3 Answers. 000 READDATE >= DATEADD(month, DATEDIFF(month, 0, GETDATE()) - 12, 0) -- < 2016-04-01 00:00:00. TIMESTAMP Functions. The first week of the year is 1. This post has been answered by 630199 on Jun 1 2009. oracle; datediff; or ask your own question. mysql> SELECT something FROM tbl_name-> WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= date_col; The query also selects rows with dates that lie in the future. PROJECTID, PROJ_TASK. It has been tested on a wide range of years (including leap ones) and more than 700k combinations of dates (including end of every months). Hot Network Questions Murder mystery, probably by Asimov, but SF plays a. create or replace function FUN_DATEDIFF ( dateFrom in date, dateTo in date, interval in char return number AS result number; beginThe default is zero (0). SYSTIMESTAMP). This function is not sensitive to the NLS_CALENDAR session parameter. This page provides you with the most commonly used Oracle date functions that help you handle date and time data easily and more effectively. Thanks in advance for any help; this has been driving us crazy for a few months now. 0. Compare dates problems. 032258the problem lies in the fact that a month is a nebulous thing - it is not a precise number of days. The DATEDIFF() function returns the number of days between two date values. Month-difference between any given two dates: Have a look at the TIMESTAMPDIFF () function in MySQL. @asfasas You can always convert the results using a proper mask. Note that the syntax for datediff () uses the SQL Server version of the function. Share. Note that SQL Server DATEDIFF(month, date2, date1) function does not return exactly the same result, and you have to use an user-defined function if you need to fully emulate the Oracle MONTHS_BETWEEN function (see. startdate, SYSDATE) Keep in mind that MONTHS_BETWEEN. 264k 58 58 gold badges 366 366 silver badges 409 409 bronze badges. 2. However, The problem is different number of records because DATEDIFF(month,a,b)<=4 in SQL Server returns only the month difference whereas months_between(a,b)<=4 in oracle returns the. Parameter Description; date1, date2: Required. SELECT DATEADD ( year, DATEDIFF ( year, 0, GETDATE ()), 0 ) 這個 SQL 的技巧是先取得和 1900-01-01 - 也就是上面的 0 的意思,SQL Server 中的第零天 - 差幾年 (從 DATEDIFF 得到一個整數),再用 DATEADD 加 0 來將整數再轉成日期的型態。. To calculate the number of days between date1 and date2, you can use either Day of. I don't think that you need to write your own timestampdiff function since oracle already has one: EXTRACT. startdate, SYSDATE) Keep in mind that MONTHS_BETWEEN() will return fractions of months, so use TRUNC() or ROUND() if you need an integer number. from a date time value. 0 and later: Fusion OTBI Analysis - How to Convert Date of Birth to Age. January 1 of any year defines the starting number for the week datepart, for example: DATEPART (wk, 'Jan 1, xxxx') = 1, where xxxx is any year. So, this expression converts SYSDATE to a string, using whatever local settings are on your system. 14977 Days 7 Hours 36 Minutes 56 Seconds. 997268. Tarek Fathy Nov 18 2010 — edited Nov 18 2010. , for the Oracle database: sale_date >= TRUNC (sysdate) AND sale_date < TRUNC (sysdate + INTERVAL '1' DAY) Another common obfuscation is to compare dates as strings as shown in the following PostgreSQL example:Oracle/PLSQL - DateDiff. The days are in two different, adjacent months, so the answer is 1 month difference. Getting the months and years between two dates using Datediff There is a round up issue with the Datediff function. – user330315. To create the rows, use the month generation technique above. When you multiply it by 24 (number of hours in a day), 60 (number of minutes in an hour) and 60 (number of seconds in a minute), the result is number of seconds (DIFF_SECS). January 30, 2004 - 7:26 pm UTC. January 30, 2004 - 7:26 pm UTC. . First put a start date in a cell, and an end date in another. datediff (q,start date,end date) i. The following example illustrates how to use the. DATEDIFF. WHERE -- >= 2016-02-01 00:00:00. mm') 16. This previous question indicates that there is a date format in Oracle that would make your year 92 into 2092 (i. Syntax:This expression: to_date(SYSDATE, 'yyyy-MM-dd') doesn't make sense. 365 / 365. (Oct 2006 - June 2005 = 16) DP_WEEK returns the distance between the weeks capturing the input dates. Improve this answer. For example, using the standard SCOTT. This post has been answered by 630199 on Jun 1 2009. Get the number of months between two dates. Select * from table where date is between '01-JAN-02' and '17-JAN-02'. You need to use DATEADD - not DATEDIFF. 25) This seems to be another common approach - and was also given in a comment on my question. Viewed 2k times. Multiply by 24 -- hours, multiply by 60 minutes, multiply by 60 -- seconds. What I want to do is, given a date (say today) work out the correct Offset in the PatternDetail table for a given working pattern. . date1. If I've got it right. Table 9. 8. The two date fields are "timestamp" format (date and time). HEH! One big difference you’ll find is that adding or subtracting two date values in Oracle leaves you with a number, not a date. The basic approach to show all duration units for a period is: Find the complete. CREATE OR REPLACE FUNCTION datediff (p_what IN VARCHAR2, p_d1 IN DATE, p_d2 IN DATE) RETURN NUMBER /* Updated to reflect current database and PL/SQL. Just out of curiosity, have you paid the $95 for a manual yet? ;-) If not, get the thicker one when you do unless you are pretty familiar with the commands and just need a reference. I m used to sql server. CREATE OR REPLACE FUNCTION dateDiff ( p_dt1 IN DATE, p_dt2 IN DATE ) RETURN NUMBER IS BEGIN RETURN p_dt1 - p_dt2; END; datediff('MONTH', pr. Oracle SQL Hours Difference between dates in HH:MM:SS. DP_QUARTER returns the distance between the quarters capturing the input dates. In case the full DDL for the database is requested, I can provide it (although it will probably exceed the character limit of Stackexchange). I have a request to build a set of worksheets that accept an intial parameter - Start Date in the format MMM YYYY. Conversion between time units is also allowed; you can add, subtract, or compare dates by using days and state. 0 for the month differnce the standard sql is DATEDIFF, in this function you must pass 3 params, if you must calculate the difference from 2 columns, c1 and c2, you must do this query . 25 = 0. 2. select datediff (q,'03-30-2005','04-01-2005') will return 1. Functions. i. Dates are always a joy to work with in any programming language, SQL not excluded. 0. Here is a PostgreSQL function with the exact same behavior as the Oracle MONTHS_BETWEEN function. 1. Asked 6 years, 5 months ago. I was following along with the toad workbook 101 video (Toad Data Point Workbook 101: The Ins and Outs) and really wanting to replicate the presenter's use of the date diff() function. DateDiff<firstWeekDay>(Date1, Date2, Unit). Oracle SQL - CASE in a WHERE clause. I suggest to use "months_between" function because it takes leap years into account (months_between wants 2 dates as parameters): select months_between(sysdate, to_date('1994-08-13', 'YYYY-MM-DD'))/12 from dual; 26,4729751904122. For example, from 2/10 to 3/10 is considered one month, and from 2/10 to 3/15 is also considered one month. 3. For example, suppose you have values below the start and end times. MONTHS_BETWEEN = 1. Warning: If the Start_date is greater than the End_date, the result will be #NUM!. So, Feb-28 to Mar-28 is a month. MySQL DATEDIFF: Calculating weeks, months, or years between two dates. trunc ( months_between ( end_date, start_date ) /12 ) Years, mod ( trunc ( months_between ( end_date, start_date ) ), 12 ) months, end_date - add_months (start_date,trunc ( months_between (end_date,start_date) )) days. Share. dbeaver. Expressions that return a value of any of the following built-in data types: a date, a timestamp, a character string, or a graphic string. Voila! You've the the last day of the month containing your reference point in time. 3. Do this even for a single day—e. select trunc ( (sysdate - to_date ('2012-02-28 15:20', 'YYYY-MM-DD hh24:mi')) / 24) from dual; You should have multiplied by. And this may raise an issue for leapers (someone born on the 29th of Feb), as taken from Wikipedia: The effective legal date of a leapling's birthday in non-leap years varies between jurisdictions. NEXT_QUARTERDatediff between dates, but exclude extra leap year day Forum – Learn more on SQLServerCentral. The number is the number of seconds elapsed since midnight, January 1, 1970. DateDiff is use d to calculate the length of time between two dates. 9. CODE = 'CONTACT_CLIENT' THEN a. In SQL Server 2012 you can use EOMONTH (Transact-SQL) to get the last day of the month and then you can use DAY (Transact-SQL) to get the number of days in the month. DaysInMonth Returns the number of days in the specified month and year. +1 This will work for every year difference. My DOB- 02-feb-1984 so my age should get as 27 Years 2 months 8 days How to do it. You can't transform this value to date by to_date function. Sorted by: 193. SELECT * FROM TABLE_NAME WHERE DATEADD (DAY, -90, GETDATE ()) between txtFromDate and txtToDate. The DATEPART () function returns an integer value that represents a specified part of the date of a given date. 1. Here are the 10 federal holidays a year, almost one per month: New Year’s Day on January 1; Martin Luther King’s Birthday on the. select level rn from dual connect by level <= 3; RN 1 2 3. Again, under Column Tools you have the option for Sort by column. Would give you rows where date2 (the later date) is 60 to 90 days later than date1. 0 ELSE 0 END AS 'MonthDifference'. Oracle equivalent to SQL Server/Sybase DateDiff. Share. date]-90) - my comparison subtracts 90 days from the max date Yes, I know,. To get the number of months you could use months_between. MONTHS_BETWEEN gives the number of whole months between the 2 dates, and calculates the fractional part as the remainder in days divided by 31. SELECT TIMESTAMPDIFF (MONTH, '2012-05-05', '2012-06-04') -- Outputs. FLOOR (DATEDIFF (DAY, date_of_birth, reference_date) / 365. USE MASTER GO -. A) Get the difference in months of dates on the same day The following example returns a difference in months between two dates: July 01 2017 and January 01 2017: SELECT MONTHS_BETWEEN ( DATE '2017-07-01', DATE '2017-01-01' ) MONTH_DIFF FROM. Javascript. This field level rule lets you display the difference between two dates. As with day to second intervals, the format for this is fixed. select (dt1-dt2) * 24 * 60 * 60 from t; dt1-dt2 gives diff in days (eg: 1. If the days of the month are both the last day of the month (e. If month is the same in both dates: results for month is negative. The MONTHS_BETWEEN function returns an estimate of the number of months between two arguments. For a baby born 28-Feb-17, properly calculated they turn 1 years old on 28-Feb-18 - their next birthday. Each Standard calendar week is defined to start on Sunday and it spans 7 days. Would give you rows where date2 (the later date) is 60 to 90 days later than date1. - Find the “date_diff” in minutes and add it with the “date_diff” in hours and the “date_ diff” in days. Function. From the inputs you got there are 123 months between the date of 07/03/2011 to 24/3/2021. It returns a whole month (no fraction) if both dates have the same day-of-month or. edited May 15, 2013 at 7:42. lastModified - w. Write queries for continuous periods as explicit range condition. Step-7: SQL Query to Calculate the Number of Months between two specific dates : Now let’s find the number of months between the dates of an order of ‘Maserati’ and ‘Ferrari’ in the table. If date1 is later than date2, then the result is positive. The date argument is a DATE value (or an expression that resolves to a DATE value) that should be rounded. I had a problem with a date query using the operator 'between'. user637544 Jun 1 2009 — edited Jun 1 2009. The part to return. You have the option to change the data type there. If you want an integer number of days. Examples. You've told it to compare the. I want to calculate the difference between two dates in OBIEE10g in Year/Months/Days format similar to the output of below SQL. datediff isn't a function in Oracle. it does not give me the records marked with a date '17-JAN-02'. For formatting functions, refer to Section 9. Asked 9 years, 7 months ago. The datepart value cannot be specified in a variable, nor as a quoted string like 'month'. , year, quarter, month, day, hour, minute, second), startdate is the starting date or time, and enddate is the ending date or time. As you can see it means that month. Sorted by: 10. (The valid formats 1,7,10,11 will be described later. When subtracting two date datatype values, the result is number of days. Here is my datediff function code. How to calculate years of experience from date_of_hiring to till date in months of an employee using sql query. What this allows you to do is pass in two TIMESTAMP or DATETIME values (or even DATE as MySQL will auto-convert) as well as the unit of time you want to base your difference on. 一重引用符で囲んだ'YYYY-MM-DD[*HH:MI[:SS]]'形式の文字列(*はコロン(:)または空白でも可)、または現在の日付を返す引用符なしの@DATENOW. user637544 Jun 1 2009 — edited Jun 1 2009. It means that the DATEPART function returns the number of times the boundary between two units is crossed. 99. ;-). COMPUTE days3 = CTIME. In this, we will add the number of years that we expect this person to turn in a given year, based on the DATEDIFF( ) results. Each Standard calendar week is defined to start on Sunday and it spans 7 days. We will use the below date for the examples. MySQL DATEDIFF: Calculating weeks, months, or years between two dates. DATEDIFF Examples Using All Options. You can even find the number of hours, minutes, seconds, and so on in terms of details in. Getting the age in terms of YEARS and MONTHS is easy, but the tricky part is the the DAYS. ) and rest are two dates which you want to compare. floor(months_between(sysdate, dateofbirth)/12) But, months_between function treats end of month day specially.