Calculate Age with Julia | Kovolff
Channel: prelearn
Date: 2020-11-22

In this video we build a module in the Julia programming language to calculate ages of living entities or persons. This module has a function, which takes one parameter - the entity’s birthdate in form of a string.

Step 1: include the Dates package
This can be done either with using or import
i.e. 
using Dates
or
import Dates

When using import you have to supersede each method call with Dates.
i.e. Dates.today()

With using, you need this, i.e. today()

Step 2: initialize your variables
i.e. 
age = 0
date_today = today()

And convert the input string to a date
i.e. birth_date = Date(birth_date_string)

Step 3 Set up your logic
 if month(birth_date) [smaller than]  month(date_today)
        age = year(date_today) - year(birth_date)
 elseif month(birth_date) [equals] month(date_today)
        if day(date_today) [greater than or equal] day(birth_date)
            age = year(date_today) - year(birth_date)
        else
            age = year(date_today) - year(birth_date) - 1
        end
else
        age = year(date_today) - year(birth_date) - 1
end

#julia #programming #date