Jump to content
php.lv forumi

Recommended Posts

Posted (edited)

Sveiki,

 

Kā lai no padotajiem datiem (Gads, Mēnesis, Diena) iegūstu lietotāja vecumu ?

Edited by Mikijs
Posted

vairaak interese php variants, jo dati nenak no SQL bet gan no lietotaja padota POST masiva.

 

$bd[year]

$bd[day]

$bd[month]

Posted

tatad dabuuuju pats ja nu kadam vajag

	function getAge($y,$m,$d){
		$year_diff = date("Y") - ($y);
		$month_diff = date("m") - ($m);
		$day_diff = date("d") - ($d);
		if ($month_diff < 0) $year_diff--;
		elseif ($month_diff == 0 && $day_diff < 0) $year_diff--;
		return $year_diff;
}

Posted

<?php

 

$dob = '1984-12-30';

 

$age = date('Y') - date('Y', strtotime($dob));

if (date('md') < date('md', strtotime($dob))) {

$age--;

}

 

echo $age;

?>

×
×
  • Create New...