tags:

views:

211

answers:

2

How would one keep a DOB field private from others if it is used to display the users age? For example, how is stackoverflow Birthday field kept private from other users? When is the display field Age changed? Is it changed just on the first of each month or randomly within an random range of Birthday? Or maybe just at the first of each year?

+1  A: 

I can't speak conclusively, but I know that the age in my SO profile rolled over, as expected, on my birthday. I suppose someone could scan the SO profiles daily and record the ages, then identify someone's birthday by when they change, but if someone wants to know that badly, I guess they can know. If you're really concerned about your privacy, don't put in your real birthday (or don't put one in at all).

Also, either intentionally or unintentionally, the user ages provided in the data dump aren't always accurate. I suspect that it's (current year)-(birth year), which leads to an age in the dump (22, in my case) that's 1 more than the user's actual age (I'm actually 21).

Kyle Cronin
A: 

Surely the value is calculated everytime you visit the Profile page. It would be far too intensive to be calculating and storing everyone's age constantly.

Of course if you have a class of type Profile, you'd simply make it a readonly property!

Something like:

public static int CalculateAge(DateTime birthDate) {

    DateTime today = DateTime.Today;

    int personAge  = (today.Year - userBirthDate.Year);
    // deduct a year if the birthday hasn't passed yet.
    if ((today.Month < birthDate.Month) || (today.Month == userBirthDate.Month && today.Day < userBirthDate.Day))
        --personAge;

    return personAge;
}

Edit: also famously asked in Question 9

p.campbell