# Correction ages in database

**URL:** <https://www.ruby-forum.com/t/correction-ages-in-database/180229>\
**Category:** Rails\
**Created:** [December 15, 2009, 9:28am UTC](https://www.ruby-forum.com/t/correction-ages-in-database/180229 "2009-12-15T09:28:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@ahmet](https://www.ruby-forum.com/u/ahmet)\
**Post date:** [December 15, 2009, 9:28am UTC](https://www.ruby-forum.com/t/correction-ages-in-database/180229/1 "2009-12-15T09:28:55Z")

</div>

hi all,

I want to make a rake task.  
It contains birthday\_year as varchar column and birthday\_date as  
varchar.  
And it should calculate age as int column

I am selecting users from database like this,  
@users = User.find(:all, :conditions =\> [“deleted = 0 created\_at \> ?”,  
1.day.ago.to\_s])

for user in @users

how can I do this part???

end

My table structure looks like this

username birthday\_year birthday\_date age created\_at  
aaa 1990 8 8 2009-12-14 11:02:16.000  
abb 8 8 2009-12-15 12:02:16.000  
abc 1980 2009-12-15 12:02:16.000  
ccc 1980 01 01 2009-12-15 12:02:16.000

for this indicator, “aaa” and “ccc” have got correct dates and I want to  
calculate their ages and update the their age columns.

I hope explained it clearly.  
How can I do it? Please help me.

---

<div class="post-metadata">

**Author:** ![ahmet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@ahmet](https://www.ruby-forum.com/u/ahmet)\
**Post date:** [December 15, 2009, 2:47pm UTC](https://www.ruby-forum.com/t/correction-ages-in-database/180229/2 "2009-12-15T14:47:19Z")

</div>

Ahmet K. wrote:

> hi all,
> 
> I want to make a rake task.  
> It contains birthday\_year as varchar column and birthday\_date as  
> varchar.  
> And it should calculate age as int column
> 
> I am selecting users from database like this,  
> @users = User.find(:all, :conditions =\> [“deleted = 0 created\_at \> ?”,  
> 1.day.ago.to\_s])

If you go to [www.ruby-forum.com](http://www.ruby-forum.com) and do a search for ‘age’ in the Rails  
forum, you’ll find a few topics which detail how to handle age  
calculation in a more elegant manner, and which, I think, will satisfy  
you.
