abhi wrote:> how can i calculate the age of a person using database " birth
date"
>
> my teble is user and column is bday ....
> now i want to calculate the age will some one please tell me how can i
> calculate the age..
>
> actually i want to compare my two database fields birthdate and
> joining date ......that is why i need this....
>
> will someone please tell me how can i do that
Does this help?
def age(dob)
now = Time.now
# how many years?
# has their birthday occured this year yet?
# subtract 1 if so, 0 if not
age = now.year - dob.year - (dob.to_time.change(:year => now.year) >
now ? 1 : 0)
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---