locked
Birthday Field Type RRS feed

  • Question

  • Staff info is stored in a public contacts based SharePoint list. There is a native Birthday field (simple date type). There are 2 problems with it:

    1. Filtering \ Stafflist can not be filtered so that it would show only people who have birthdays [Today] which leads to second problem
    2. It includes year \ And filtering is one issue with it, another is privacy - people would not like their age to be shown to everyone.

    What are the options to solve it ? Anything besides coding a custom field ?

    Sunday, May 8, 2011 10:02 AM

Answers

  • If you do a custom new and edit form in infopath, you can create a month dropdown picker and day dropdown picker and on submit combine the value - I think in this case the sharepoint list field type would be single line of text, because its really not a date...
    • Marked as answer by KeFang Chen Sunday, May 15, 2011 3:12 AM
    Sunday, May 8, 2011 10:39 PM

All replies

  • You could keep the simple date field the way it is and use a workflow/event handler/timer job on the list to update the year component of the birthday to be either this year (if their birthday has not happened yet this year) or next year (if it has). I'm thinking something along these lines:

     

    try
    {
     SPListItem item = properties.ListItem;
     DateTime dtBirthday = DateTime.Parse(item["Birthday"].ToString());
    
     // Compare month and day components to the same month and day this year
     // to determine if the birthday has already occurred this year
     DateTime dtBirthdayThisYear = new DateTime(DateTime.Now.Year, dtBirthday.Month, dtBirthday.Day);
     if (dtBirthdayThisYear.CompareTo(DateTime.Now) < 0)
     {
     // The birthday has already occurred, set the field to next year
     item["Birthday"] = new DateTime(DateTime.Now.Year + 1, dtBirthday.Month, dtBirthday.Day);
     }
     else
     {
     // Set the birthday field to this year
     item["Birthday"] = dtBirthdayThisYear;
     }
    
     item.SystemUpdate();
    }
    catch (Exception ex)
    {
     LogException(ex.Message, ex.StackTrace);
    }
    

     

    Obviously this code would need to run often enough to update everyone's birthday years as the birthdays occur, but then you could at least use a [Today] filter on the list to see who has a birthday today.

     

    Danny Jessee
    MCTS - SharePoint 2010 Application Development


    dannyjessee.com/blog

    • Proposed as answer by dannyjessee Sunday, May 8, 2011 12:36 PM
    Sunday, May 8, 2011 11:33 AM
  • If you do a custom new and edit form in infopath, you can create a month dropdown picker and day dropdown picker and on submit combine the value - I think in this case the sharepoint list field type would be single line of text, because its really not a date...
    • Marked as answer by KeFang Chen Sunday, May 15, 2011 3:12 AM
    Sunday, May 8, 2011 10:39 PM