I need a help.

I have a SQL SERVER database where I have put persons with their birthdate. I need to calculate ages of them. For examble my birthdate is 12/27/1982 and I have to debit (minus) from current date.

Does anyone have any idea how to solve this problem.

Use the SQL DATEDIFF function.

DATEDIFF( datapart, date_expression1, date_expression2)

i.e.

DATEDIFF (year, '1/1/1999', '1/1/2000')   

[b] would give [u]1[/u] as a result [/b]

Hope that helps

Happy coding :cool:

Member Avatar for Electrohead

Sounds tricky! Maybe you could adapt a javascript to suit your needs?

Tricky?

And what does Javascript have to do with SQL functions?

The function is simple.... how is it tricky?
:?::?:

Sounds tricky! Maybe you could adapt a javascript to suit your needs?

I still get error on calculation, but it is syntax error.

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'year'.

Where could be the problem.

Anyway thanks I already fixed the problem. Thnaks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.