October 12, 2009 at 7:24 am
This query is producing the following error
Select Top 10 Firstname, Middlename, surname, year(convert(varchar,dateofbirth,103)) - year(convert(varchar,Getdate(),103)) from biodata
Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
ANY HELP
kshitij kumar
kshitij@krayknot.com
www.krayknot.com
October 12, 2009 at 7:34 am
Why are you converting to a varchar ? varchar(what) by the way ? if you dont specify it defaults to 1
select Top 10 Firstname, Middlename, surname, year(dateofbirth) - year(Getdate()) from
biodata
This wont calculate an age correctly, try...
select CASE
WHEN dateadd(year, datediff (year, d1, d2), d1) > d2
THEN datediff (year, d1, d2) - 1
ELSE datediff (year, d1, d2)
END as Age
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy