Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Rno Name Dob
1 Raman 12-Jan-1997
2 Shweta 15-Dec-1967
3 Kamal 02-May-1982
4 Bhuvnesh 19-Jun-1978

What I have tried:

SQL> select
2 Name
3 ,YEAR(Dob) AS [BirthYear]
4 ,YEAR(GETDATE()) AS [ThisYear]
5 ,YEAR(GETDATE())-YEAR (Dob) AS [AGE]
6 From
7 New;
Posted
Updated 27-Apr-21 2:07am
Comments
CHill60 27-Apr-21 5:03am    
And what is wrong with your code?
What results are you expecting from the data you have given us?
Kushal Kadel 27-Apr-21 5:32am    
Rno Name Dob Age
1 Raman 12-Jan-1997 22
2 Shweta 15-Dec-1967 51
3 Kamal 02-May-1982 37
4 Bhuvnesh 19-Jun-1978 41

I want Age by subtraction of Dob from given ques date 18-09-2019.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
There are a good number of SQL Date functions you can use to get date parts (such as year, month, day) and the difference between dates in various way.

I suggest you look here[^] and then solve your problem.

The link is a starting point - it's important you learn to handle dates comfortably as soon as possible if you plan on using SQL. You can do a similar search for MySQL if that is your database.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900