
A Ruby function for extracting one's age by passing in the birth date as a parameter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def birthdate_to_age(birthdate) #bDate must be in the date-time format | |
age = Date.today.year - birthdate.year | |
if Date.today.month < birthdate.month || (Date.today.month == birthdate.month && birthdate.day >= Date.today.day) | |
age = age - 1 | |
end | |
age.to_s | |
end |
No comments:
Post a Comment