TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hakan Axheim
NA
201
32.1k
Calculate age between current date and birthdate
Feb 22 2019 5:53 AM
Hi,
I want to calcute the diffence between current date and the date a person is born in year.
Birthday is stored in a column with vachar(12).
I try this SQL statement:
SELECT CONVERT(DATETIME,LEFT(birthdate,8),120), DATEDIFF(YEAR,CONVERT(DATETIME,LEFT(birthdate,8),120),getdate()) as 'Age' from Person
The funny thing with this SQL is if a person is born
201809234247
(social security number) and the current date is 2019-02-22 the age result will be 1 year. This is not true - it should be 0.
Something is wrong with my SQL statement but what?
Reply
Answers (
4
)
Out of four option choose the one answer agnist the question
sql cte to join two results in one common