Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datediff expression question in SQL & using current date 2

Status
Not open for further replies.

rhardy99

MIS
Dec 19, 2003
21
US
Using the datediff expression, I would like to get the amount of years from a DATE OF BIRTH field minus the current date. Is the variable for current date =CURDATE?
For example: datediff(yy,date_of_birth,curdate)
This doesn't seem to work, however I can change curdate to another date from a different feild like so....
datediff(yy,date_of_birth,date_of_death) ..this produces the years ok. Maybe i can't use CURDATE with the DATEDIFF expression?
Thanks,
Russ "SQL Newbie
 
getdate() will give you the current date

select datediff(yy,date_of_birth,getdate())

Tim
 
Thank you so much. I have a SQL Sybex book and I don't see that anywhere. Could be my fault in not looking up the right info, but on all pages referenced to datediff, getdate() was never mentioned. Thank you very much!!
oh..the statemet worked great!!!
Thanks again Tim!
Russ
 
Russ,

You ARE using Microsoft SQL Server aren't you???

I suggest refering to the BOL.

BOL= Books OnLine = Microsoft SQL Server's Help
Installed as part of the Client Tools
Found at Start>Programs>Microsoft SQL Server>Books OnLine

-SQLBill
 
Thanks SQLBill!
I never used the BOOKS ONLINE. I did a search for CURRENT DATE and in the FOUND list of 154 other items it did have the GETDATE.
Thank you for pointing out a reference for me besides my Sybex SQL book.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top