Skip to content

Calculating Facebook user’s total work experience

January 3, 2013

Well, solving it went faster than I expected. Here’s the code used to calculate a Facebook user’s total work experience. There’s no doubt an easier and prettier way to do this, but it works and that’s enough for a virgin coder like me. Note that the code below is just for the calculation, it does not contain the rest of the code dealing with authenticating with FB etc. 

// this calculates the amount of total work experience automatically from FB

$totalWorkExperience = 0;

foreach($user_info['work'] as $employer)
{
$currentWorkStartDate = $employer['start_date'];
if ($employer['end_date'] == “0000-00″) {
$currentWorkEndDate = Date(‘Y-m’);
} else {
$currentWorkEndDate = $employer['end_date'];
}

$dateStarted = new DateTime($currentWorkStartDate);
$dateEnded = new DateTime($currentWorkEndDate);
$interval = $dateStarted->diff($dateEnded);
$totalWorkExperience += $interval->days;

}

// Figure out how many years the experience in days amounts to, rounding to the closed full year

$totalWorkExperienceInYears = round($totalWorkExperience/365);

 

About these ads

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: