# Calculate Age in SQL that is >= 60

Page 1 of 1

## 11 Replies - 485 Views - Last Post: 09 March 2018 - 11:48 AM

### #1 DanZman

Reputation: 0
• Posts: 51
• Joined: 24-January 18

# Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:22 AM

I'm trying to display salaries for employees that are or older than 60yrs of age.

I have a column with the birthdate listed "birth_date" format "160-01-20"

I tried doing this in the where clause
```CURDATE() - employees.birth_date >= 60

```

However, it doesn't return the accurate information.

Any help is appreciated.

Thanks,

DanZman, on 09 March 2018 - 10:19 AM, said:

I'm trying to display salaries for employees that are or older than 60yrs of age.

I have a column with the birthdate listed "birth_date" format "1960-01-20"

I tried doing this in the where clause
```CURDATE() - employees.birth_date >= 60

```

UPDATE sorry, in the original post I didn't have the year in the birth_date correctly.
However, it doesn't return the accurate information.

Any help is appreciated.

Thanks,

Is This A Good Question/Topic? 0

## Replies To: Calculate Age in SQL that is >= 60

### #2 modi123_1

• Suitor #2

Reputation: 14845
• Posts: 59,246
• Joined: 12-June 08

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:26 AM

Perhaps show the relevant code around that for folk to get a better idea what you are doing.

### #3 DanZman

Reputation: 0
• Posts: 51
• Joined: 24-January 18

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:28 AM

This is the full code

```use employees;
SELECT
employees.first_name, employees.last_name, salaries.salary
FROM
employees
JOIN
salaries ON employees.emp_no = salaries.emp_no
WHERE
CURDATE() - employees.birth_date >= 60

GROUP BY first_name

```

### #4 modi123_1

• Suitor #2

Reputation: 14845
• Posts: 59,246
• Joined: 12-June 08

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:28 AM

Any particular reason you opted against using a SQL function like 'DATEDIFF'?

### #5 DanZman

Reputation: 0
• Posts: 51
• Joined: 24-January 18

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:30 AM

modi123_1, on 09 March 2018 - 10:28 AM, said:

Any particular reason you opted against using a SQL function like 'DATEDIFF'?

I tried using it but I got an error about an incorrect parameter count in the call.

This is what I had for DATEDIFF
```DATEDIFF(yy, CURDATE(), employees.birth_date)

```

### #6 modi123_1

• Suitor #2

Reputation: 14845
• Posts: 59,246
• Joined: 12-June 08

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:35 AM

I would have to see what you tried and the exact error message. In theory that should work.

### #7 DanZman

Reputation: 0
• Posts: 51
• Joined: 24-January 18

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:38 AM

modi123_1, on 09 March 2018 - 10:35 AM, said:

I would have to see what you tried and the exact error message. In theory that should work.

Below is the code and the error message was "Incorrect parameter count in the call to native function DATEDIFF'
```use employees;
SELECT
employees.first_name, employees.last_name, salaries.salary
FROM
employees
JOIN
salaries ON employees.emp_no = salaries.emp_no
WHERE
DATEDIFF(yy, CURDATE(), employees.birth_date) >= 60
GROUP BY first_name

```

### #8 modi123_1

• Suitor #2

Reputation: 14845
• Posts: 59,246
• Joined: 12-June 08

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:38 AM

Which DB is this? MSSQL, MYSQL, ORACLE, etc?

### #9 DanZman

Reputation: 0
• Posts: 51
• Joined: 24-January 18

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:39 AM

modi123_1, on 09 March 2018 - 10:38 AM, said:

Which DB is this? MSSQL, MYSQL, ORACLE, etc?

MySQL Workbench

### #10 modi123_1

• Suitor #2

Reputation: 14845
• Posts: 59,246
• Joined: 12-June 08

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:42 AM

Ah.. well the docs indicate:

Quote

DATEDIFF() returns expr1 − expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

https://dev.mysql.co...nction_datediff

If you don't want to work with days then alternatively you can peep at the 'year' function.
https://dev.mysql.co...l#function_year

### #11 DanZman

Reputation: 0
• Posts: 51
• Joined: 24-January 18

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 10:46 AM

modi123_1, on 09 March 2018 - 10:42 AM, said:

Ah.. well the docs indicate:

Quote

DATEDIFF() returns expr1 − expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

https://dev.mysql.co...nction_datediff

If you don't want to work with days then alternatively you can peep at the 'year' function.
https://dev.mysql.co...l#function_year

I See thanks for your help!

### #12 g00se

• D.I.C Lover

Reputation: 3617
• Posts: 16,593
• Joined: 20-September 08

## Re: Calculate Age in SQL that is >= 60

Posted 09 March 2018 - 11:48 AM

Try
```SELECT first_name, last_name, birth_date FROM employees WHERE birth_date <= date_add(curdate(), INTERVAL -60 YEAR);
```