Calculate User Age
<?php
$years = "1985"; //Assigned year of birth - This is the area you can pass your user's birth year
function calculateAge($birthdate)
{
return floor((time() - strtotime($birthdate))/31556926);
}
print calculateAge($years)." year(s)"; //This one displays the user's actual age
?>
Calculate Days Remaining Till User Birthday and also User Age
<?php
function vpb_calculate_user_birthday($birthdate)
{
//If the user refuses to specify a birthday, just set today as birthday by default
if(empty($birthdate)) { $vpb_birthday_year_month_day = date("Y-m-d"); }
else { $vpb_birthday_year_month_day = $birthdate; }
// Current date which is today's date
$vpb_todays_date = date('Y-m-d');
//Get the Year, Month, Day from the given date of birth
$vpb_todays_date_array = explode('-',$vpb_todays_date);
$vpb_birthday_year_month_day_array = explode('-',$vpb_birthday_year_month_day);
//Pass Year, Month, Day to one variable as the user birthdate
$vpb_formatted_birthdate = $vpb_todays_date_array[0]."-".$vpb_birthday_year_month_day_array[1]."-".$vpb_birthday_year_month_day_array[2];
$vpb_date_difference = strtotime($vpb_formatted_birthdate)-time();//Current time returns in seconds
$vpb_age_calculation = time() - strtotime($vpb_birthday_year_month_day_array[0]);
// Days remaining till user birthday
$vpb_remaining_days = floor($vpb_date_difference/round(60*60*24));
//User age
$vpb_user_age = floor(($vpb_age_calculation)/round(60*60*24*365)); //31556926
if(strtotime($vpb_formatted_birthdate) < time())
{
$vpb_result = "Your birthday has passed for this year";
$vpb_result .= $vpb_user_age.' Years<br>';
}
else
{
if($vpb_remaining_days == 0)
{
$vpb_result = "Today is your birthday, Happy Birthday :) <br>";
$vpb_result .= $vpb_user_age.' Years<br>';
}
else
{
$vpb_result .= $vpb_remaining_days.' days remaining till your birthday<br>';
$vpb_result .= round($vpb_user_age-(1)).' Years<br>';
}
}
return $vpb_result;
}
//Birth Date Format: YYYY-MM-DD
echo vpb_calculate_user_birthday('1982-12-21');
?>
Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.
We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.
Copyright © 2011 - 2024 | All Rights Reserved