function takes a person's birthday in year-month-day format and % calculates the number of days until their next birthday from the current % date in matlab

main.m
function daysUntilNextBirthday = calculateDaysUntilNextBirthday(birthday)
    currentYear = year(datetime('today'));
    nextBirthday = datetime(currentYear, month(birthday), day(birthday));
    
    if nextBirthday < datetime('today')
        nextBirthday = datetime(currentYear+1, month(birthday), day(birthday));
    end

    daysUntilNextBirthday = days(nextBirthday - datetime('today'));
end
397 chars
11 lines

related categories

gistlibby LogSnag