vba - Visual Basic: Calculating days until birthday from today -


i need make function calculates days until birthday todays date. have far is:

function synnipaev(sk date, tana date)  synnipaev = datediff("d", sk, tana)  end function 

sk birthdate in excel sheet (formated 10.10.2001 dd/mm/yyyy)

tana todays date in excel sheet ( =today() dd/mm/yyyy)

it gives me days includes years. how make function not include years?

datediff giving total number of days between 2 dates. need find difference between current date , next birthdate:

public function daystobirthday(birthday date) integer      dim targetyear integer      'has birthday passed year?     if month(now) > month(birthday) or _        (month(now) = month(birthday) , day(now) > day(birthday))         'then use next year.         targetyear = year(now) + 1     else         targetyear = year(now)     end if      daystobirthday = cint(dateserial(targetyear, month(birthday), day(birthday)) - now)  end function 

note: vba stores date variables doubles, days left of decimal , time right. if care days, can save function call , simple subtraction.


Popular posts from this blog