I have a table which has date of births of some employees. How can I find the age difference between two employees?
subtract two dates from a table in sql
381 views Asked by Binary Terror At
2
There are 2 answers
1
mahi_0707
On
Can you try the below to get days , months and years between two dates.
DECLARE
dob1 date := TO_DATE('11-17-2015','MM-DD-YYYY'); -- change your dates here
dob2 date := TO_DATE('11-18-2012','MM-DD-YYYY');
v_years varchar2(100);
v_months varchar2(100);
v_days varchar2(100);
BEGIN
select (abs(dob1 - dob2)) into v_days from dual;
DBMS_output.put_line('DAYS : ' || v_days);
select floor(abs(dob1 - dob2)/365) into v_years from dual;
DBMS_output.put_line('YEARS : ' || v_years);
select floor(abs(dob1 - dob2)/365*12) into v_months from dual;
DBMS_output.put_line('MONTHS : ' || v_months);
END;
/
OUTPUT:
DAYS : 1094
YEARS : 2
MONTHS : 35
PL/SQL procedure successfully completed.
Related Questions in SQL
- SQL schema for a fill-in-the-blank exercise
- Hibernate: JOIN inheritance question - why the need for two left joins
- What's supposed to be the problem in this query?
- Compare fields in two tables
- How to change woocomerce or full wordpress currency with value from USD to AUD
- Dynamic query creation with Array like implementation
- SQL query to get student enrolled in this month in a course - Moodle
- SQL LAG() function returning 0 for every row despite available previous rows
- Convert C# DateTime.Ticks to Bigquery DateTime Format
- Use row values from another table to select them as columns and establish relations between them (pivot table)
- SQL: Generate combination table based on source and destination column from same table
- how to use system's environnement variables in sql script
- PHP fetchAll on JOIN
- Multitable joining in Sql
- How to display name starting from 'z' by using BETWEEN cmd only?
Related Questions in ORACLE
- sqlplus myusername/mypassword@ORCL not working with Oracle on Docker
- Oracle setting up on k8s cluster using helm charts enterprise edition
- Oracle Managed Data Access Client can't work from IIS but work for local debug environment
- If composite indexing created - indexing is called?
- Oracle Http server ISNT-07551
- why here not creating table?
- Data migration from Oracle Database Clob to GCP Bucket
- SQL Alchemy custom type, forcing blob bind parameter
- How to send message to syslog agent in plsql
- Whatever the data available in previous record it should add to the new record
- I have an Oracle SQL query that is giving me a "ORA-00918: column ambiguously defined" error on a line that is a comment line
- 'ORA-12170: TNS:Connect timeout occurredORA-12170: TNS:Connect timeout occurred' ERROR while working on oracle with laravel
- Is their any way i can open parallel query tabs
- VSCode Libraries not showing for New Java Project
- I can't ssh to my instance, Connection refused
Related Questions in DATE
- Using JQuery Date Slider
- Get Type Error when using .countDocuments with mongoDB
- Gsheet - Automatically send an email using a date & time in a Cell
- Market share growth versus last month, last year
- Convert date string into a number in Python
- Date formatting "yyyy-MM-dd hh:mm:ss +0000" to "dd MMM" in swift
- How does Big Query differentiate between a day and month when we upload any CSV or text file?
- Event_date reference in CTE
- Laravel Nova 4 format date in BelongsTo field
- how to count days elpased between each interval using mySQL?
- MariaDB incorrect dates
- Date issue - how do I parse date in this SQL
- Countdown to varying payday in Javascript
- Can I have a static ISO8601DateFormatter with specific formatOptions in Swift?
- Date Format mdy vs dmy
Related Questions in PLSQL
- How to send message to syslog agent in plsql
- In PLSQL, How to fetch "User Tables" but not limited to Owner wise only, that have been created under different Schemas of different Users
- How to add the decimal point based on the condition in oracle?
- I am writing the sql query to get the latest supervisor and their job
- How to pass a array object to an oracle stored procedure?
- Difference between an "IS" or "AS" function/procedure declaration PL/SQL
- Best way to create a conditional SQL query? CASE, DECODE, or IF/THEN?
- Can anyone please post working code to send email using sendgrid on Azure databse using PLSQL procedure
- Retrieve record specific date and time in Oracle SQL
- Need to use join result into second cursor in PL/SQL
- ORACLE: Build 'INSERT INTO' statements from 'SELECT *' results
- ORACLE: Build 'INSERT INTO' statements from SELECT * results
- Error in Syntax - Oracle APEX - apex_authorization.is_authorized function
- How to convert CLOB to varchar , and separate them by comma
- Please, my Oracle EBS query when creating a custom report still contains duplicate data,
Related Questions in DATE-DIFFERENCE
- AppSheets timestamps and duration difference
- Convert months (in decimal form) to months and days that were found between two dates
- Separate data and text from one cell to provide a duration with a summary
- Excel: how do I use =datedif with conditional formatting to highlight date cells in a table?
- Python Pandas filter rows by days of difference in two columns with weekend and holidays
- Kotlin difference between two LocalDateTime
- Groovy script to break payload for every date between start and end dates
- using date for calender as an input to figure out the time difference
- SAS code to Identify records from the input having a difference of >31 days and delete
- Time duration between 2 DateTime columns EXCLUDE out of office hours - SQL BigQuery
- What is the Google Sheets formula to calculate the working hours for each specific day based on the source of the chat and the given work schedule?
- PRESTO: Calculating Date Difference Excluding Days: Precision in Months and Handling Greater Than 1 Month Condition
- What is the Google sheets formula to calculate the working hours of timestamp difference for a specific working hours?
- Check if EMIDate of next record is less than or equal to EMIdate of previous record, also calculate the Difference between 2 dates
- Get a list of months, according to financial year
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Subtracting two
datecolumns in Oracle will result in the difference in days, which you could divide by 365 to get the difference in years: