UPDATE users table with a calculated field for current_age

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ltworf13
Forum Newbie
Posts: 1
Joined: Sat Nov 09, 2013 8:00 am

UPDATE users table with a calculated field for current_age

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: UPDATE users table with a calculated field for current_a

Post 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.
Post Reply