Page 1 of 1

UPDATE users table with a calculated field for current_age

Posted: Sat Nov 09, 2013 8:16 am
by ltworf13
I have a users table which has a birthdate field. I'm trying to figure out the syntax that would allow me to loop through the table and update another field name current_age. Using somekind of calculation based of the birthdate field.

I was thinking something like

UPDATE users
SET current_age=(birth_date)/(60*60*24*365.2421896)

in some kid of a loop if I need a loop.

Re: UPDATE users table with a calculated field for current_a

Posted: Sat Nov 09, 2013 5:56 pm
by requinix
Don't store the age. It's pointless: you'd have to keep recalculating it every day.

If you need the age then do it in your code. It'll always be correct without you having to repeatedly update some age field.