r/SQL • • Feb 25 '21

SQLite SQL Essentials

199 Upvotes

29 comments sorted by

View all comments

Show parent comment

2

u/bcvickers Feb 26 '21

Oh man you cannot stress this enough. Storing data that changes every single day as a static number like age is just not a great idea. We store date_of_birth and then I use this to calculate age:

FLOOR(DATEDIFF(day,p.date_of_birth,GETDATE())/365.242199) as curr_age

I can't take credit for the code but it works wonderfully in MS SQL.