WebsiteBaker Community Forum (upd)

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: noname8 on January 27, 2012, 10:27:22 AM

Title: Calculate age droplet
Post by: noname8 on January 27, 2012, 10:27:22 AM
Just a simple droplet to calculate age in years (with decimal) and days :mrgreen:
Name
bday
Desc.

Calculate total age from birthdate years and days


code
global $MESSAGE;
$output_value ="";
$d=trim($d);
$datenow=date("Y-m-d");
$diff=strtotime($datenow)-strtotime($d);
if($diff <0)$diff=$diff * -1; //no negative values
$days=floor(($diff)/86400);
$years=round(($diff /31536000), 2);

//DEBUG
//$output_value="$datenow $d Age is $years years. That's $days days";
ENG $output_value="Age is $years years. That's $days days";

return $output_value;



comment
Use this with [[bday?d=1950-12-31]]
You can add this to any place, even in the title of a link or alt text of an image. Also future day possible.


Title: Re: Calculate age droplet
Post by: KP on July 25, 2013, 11:28:21 PM
I get This droplet has invalid PHP code.[/color] error.
Title: Re: Calculate age droplet
Post by: marmot on July 25, 2013, 11:43:35 PM
Hi,

Quote from: crevinamd on July 25, 2013, 11:28:21 PM
I get This droplet has invalid PHP code.[/color] error.
this is because of "ENG" in line 12, just delete it.

regards