Hy, i want to count years of an actor.
The date that actor is born is stored in a custom field.
$date = get_field('data_nasterii');
Date stored in custom field is : yymmdd
How can i stick bouth togeder to make it work.
<?php
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = "12/17/1967";
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2]));
echo $age ."ani";
?>
I try this but this returned me year 2012
<?php
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = get_field('data_nasterii');
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2]));
echo $age ."ani";
?>