+ Reply to Thread
Results 1 to 17 of 17

Birthday indicator formula

Hybrid View

  1. #1
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90

    Birthday indicator formula

    Hello everyone.

    I have a table with employees' persinal data including birthdays. My aim is to insert an indicating field that would show whether the birthday is gonna come soon.

    It shold have several states:
    number of days left if the birthday is current or next month
    "not soon enough" if the birthday will come in more than 2 months (later than next month);
    "happy birthday" if it is today;
    "the past weekend" if it was the past weekend and it is Monday today.

    What can you suggest?

    Thanks in advance.
    Last edited by Freaky_zoid; 12-03-2008 at 04:48 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    Formulae

    =IF(birthday_date>TODAY(),IF(birthday_date<=DATE(YEAR(TODAY()),MONTH(TODAY())+2,1),birthday_date-TODAY(),"not soon enough"),IF(birthday_date=TODAY(),"Happ birthday!",IF(birthday_date>=TODAY()-7,"The past week","")))

  3. #3
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90
    Hello, Bob.
    Thank you for the answer, but this formula doesn't work properly. Most of the cells are blank, I only get results with "happy birthday" and number of days if the birthday is in December. It doesn't count the days correctly when birthday is in January because the month number is 1 and it is less than 12 so [birthday_date<=DATE(YEAR(TODAY()),MONTH(TODAY())+2] doesn't recognize it.

  4. #4
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    The fact that Jan month number is less than Dec month number is irrelevant, the formula works on the date, not the month number.

    I just tried a birthday date of 12th Jan 2009 and it returned 42 for me.

    If the date could be blank, just pre-prend with

    IF(birthday_date="","", ...

  5. #5
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Quote Originally Posted by Bob Phillips View Post
    I just tried a birthday date of 12th Jan 2009 and it returned 42 for me..
    You're 41? still just a puppy!
    Not all forums are the same - seek and you shall find

  6. #6
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90
    Bob, I do not have blank cells in the field containing birthdays. I get blank cells when use your formula. but it's not that bad, I have fixed that, I guess.
    12th Jan 2009 is not a suitable birthday, I've got dates with years of birth. Try 12th Jan 1969.
    I'm trying now to do it using the DATEDIF function, not quite alright yet.

  7. #7
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Freaky Zoid, create a dummy workbook with some of the data you are having trouble with and then attach it here using Manage Attachments below the submit button when you post next, that way we will be able to help your further.

  8. #8
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    =IF(AND(TODAY()+61>A1,A1<>TODAY(),A1-TODAY()>0),A1-TODAY()&"  days to go",IF(TODAY()+61<A1,"not soon enough",IF(A1=TODAY(),"happy birthday",IF(AND(VALUE(TODAY()-A1)<3,OR(WEEKDAY(TODAY(),2)-WEEKDAY(A1,2)=-5,WEEKDAY(TODAY(),2)-WEEKDAY(A1,2)=-6)),"last week end",""))))
    this gives more or less 2 months away without complicating the formula too much
    now if you want to use actual birthdate then
    in b1 put birthdate e.g. 21/12/1972
    in a1 use
    =VALUE(LEFT(TEXT(B1,"dd-mmm-yyyy"),7)&YEAR(TODAY())) which will return 21/12/2008 for use in above formula (cell formated as date)
    Last edited by martindwilson; 12-01-2008 at 10:25 AM.

  9. #9
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    If you have birth dates as against birthdya dates, other than when the birthday is today, how do you know whether to test the previous birthday or the next birthday?

  10. #10
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90
    Martin, thank you, I tried your formula, but it isn't working if birthday is in January. All logical tests returm false and there is "" for false in the last IF function which makes the whole formula return blank field. I guess there should be A1-TODAY()&" days to go".
    by the way is it really necessary to use an additional field to make the birthday date this year?
    Can I put DATE(YEAR(TODAY(),MONTH(B1),DAY(B1)) everywhere istead of A1?

    Bob, I'm afraid I don't unerstand the question

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    =DATE(YEAR(TODAY()),MONTH(B1),DAY(B1)) is fine
    but formula works fine,you must be doing something wrong!(i changed the weekend bit slightly and changed the parameters for >=61 days to get rid of a blank in feb.
    see attached
    Attached Files Attached Files
    Last edited by martindwilson; 12-02-2008 at 05:25 AM.

  12. #12
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    Quote Originally Posted by Freaky_zoid View Post

    Bob, I'm afraid I don't unerstand the question
    I am saying, do I test whether my next birthday is due soon, or whether my last birthday is just past?

  13. #13
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90
    Martin, I guess I've got it. You leave it blank if the birthday has passed this year. It shall switch to "not soon enough" when today is 2009.

    Bob, this is the same thing. If your birthday has just pass, your next one is not gonna come soon. I don't need to see if the birthday has passed recently

  14. #14
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    Quote Originally Posted by Freaky_zoid View Post
    Martin, I guess I've got it. You leave it blank if the birthday has passed this year. It shall switch to "not soon enough" when today is 2009.

    Bob, this is the same thing. If your birthday has just pass, your next one is not gonna come soon. I don't need to see if the birthday has passed recently
    That is true, but which one do you test, previous or next?

  15. #15
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90
    Bob, we check the birthday this year, which can be either previos or next depending on today's date.

    I tried the DATEDIF function and here's what I've got:
    =IF(ISERR(DATEDIF(TODAY(),DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),"d")),IF(AND(DATEDIF(DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),TODAY(),"d")<=2,WEEKDAY(TODAY(),2)=1),"The last weekend",IF(AND(MONTH(A1)=1,MONTH(TODAY())=12),DATEDIF(TODAY(),DATE(YEAR(TODAY())+1,MONTH(A1),DAY(A1)),"d"),"Not soon enough")),IF(DATEDIF(TODAY(),DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),"d")<61, IF(TODAY()-DATE(YEAR(TODAY()),MONTH(A1),DAY(A1))=0,"Happy birthday",DATEDIF(TODAY(),DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),"d")),"Not soon enough"))

    Looks like working ok, but a bit too long and not easy to work with

  16. #16
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284
    Quote Originally Posted by Freaky_zoid View Post
    Bob, we check the birthday this year, which can be either previos or next depending on today's date.

    I tried the DATEDIF function and here's what I've got:
    =IF(ISERR(DATEDIF(TODAY(),DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),"d")),IF(AND(DATEDIF(DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),TODAY(),"d")<=2,WEEKDAY(TODAY(),2)=1),"The last weekend",IF(AND(MONTH(A1)=1,MONTH(TODAY())=12),DATEDIF(TODAY(),DATE(YEAR(TODAY())+1,MONTH(A1),DAY(A1)),"d"),"Not soon enough")),IF(DATEDIF(TODAY(),DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),"d")<61, IF(TODAY()-DATE(YEAR(TODAY()),MONTH(A1),DAY(A1))=0,"Happy birthday",DATEDIF(TODAY(),DATE(YEAR(TODAY()),MONTH(A1),DAY(A1)),"d")),"Not soon enough"))

    Looks like working ok, but a bit too long and not easy to work with
    Persinally, I would calculate the birthday in one cell, and then test against that value, rather than repeat the calculation of the birtday. You can reduce it to

    =IF(ISERR(DATEDIF(TODAY(),B1,"d")),
    IF(AND(DATEDIF(B1,TODAY(),"d")<=2,WEEKDAY(TODAY(),2)=1),"The last weekend",
    IF(AND(MONTH(A1)=1,MONTH(TODAY())=12),DATEDIF(TODAY(),DATE(YEAR(TODAY())+1,MONTH(A1),DAY(A1)),"d"),"Not soon enough")),
    IF(DATEDIF(TODAY(),B1,"d")<61, IF(TODAY()-B1=0,"Happy birthday",DATEDIF(TODAY(),B1,"d")),"Not soon enough"))

  17. #17
    Registered User
    Join Date
    11-24-2008
    Location
    Moscow, Russia
    MS-Off Ver
    MS Office 2003, 2007
    Posts
    90
    Bob, maybe you're right.

    I thank everyone for the help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1