Author Topic: Calculate age droplet  (Read 2911 times)

Offline noname8

  • Posts: 151
Calculate age droplet
« on: January 27, 2012, 10:27:22 AM »
Just a simple droplet to calculate age in years (with decimal) and days :mrgreen:
Name
Code: [Select]
bdayDesc.

Code: [Select]
Calculate total age from birthdate years and days

code
Code: [Select]
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
Code: [Select]
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.


Offline KP

  • Posts: 66
  • Gender: Male
    • CREVIN
Re: Calculate age droplet
« Reply #1 on: July 25, 2013, 11:28:21 PM »
I get
Code: [Select]
This droplet has invalid PHP code.[/color] error.

Offline marmot

  • Posts: 1103
Re: Calculate age droplet
« Reply #2 on: July 25, 2013, 11:43:35 PM »
Hi,

I get
Code: [Select]
This droplet has invalid PHP code.[/color] error.
this is because of "ENG" in line 12, just delete it.

regards