Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I am using SQL 2005 (the free version). I created a table to store customers. I have a field in my table for DOB and would like to add a field for AGE and calculate age by subtracting the customer's DOB from the current date. Can anyone help me do that?
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-01-18 : 11:45:12
just use
UPDATE CustomerSET Age=CASE WHEN MONTH(DOB)>MONTH(GETDATE()) OR (MONTH(DOB)=MONTH(GETDATE()) AND DAY(DOB)>DAY(GETDATE())) THEN DATEDIFF(yy,DOB,GETDATE())-1 ELSE DATEDIFF(yy,DOB,GETDATE()) END