Hi guys, had a collum brith_day and hire_ date ,i need to show empolees who had 45 yers at the moment of hire
i try to (birth_date-hire_date) = 45 but dosnt work, can someone help me? still learn it
Loading
Hi guys, had a collum brith_day and hire_ date ,i need to show empolees who had 45 yers at the moment of hire
i try to (birth_date-hire_date) = 45 but dosnt work, can someone help me? still learn it
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted Dec 4, 2023, 6:29 AM
Hello,
You can find using DateDiff() function,
Jayraj ChhayaPosted Dec 3, 2023, 4:24 PM
To find employees who were 45 years old at the time of their hire, you need to consider the date difference between their birth date and hire date. However, directly subtracting the birth date from the hire date will not yield the desired result.
In SQL, you can use the
DATEDIFF()function to calculate the age of an employee at the time of hire. TheDATEDIFF()function calculates the difference between two dates in a specified unit (e.g., years, months, days).In this query, we are using the
DATEDIFF()function to calculate the difference in years between thebirth_dateandhire_date. We then compare this difference to 45 to filter out employees who were exactly 45 years old at the time of their hire.Make sure to replace
employeeswith the actual name of your table. Additionally, ensure that the column namesbirth_dateandhire_datematch the column names in your table.By using the
DATEDIFF()function in this way, you should be able to retrieve the employees who satisfy the condition of being 45 years old at the time of their hire.