<?php function zaman($deger){ $z=array(); if(version_compare(phpversion(),'5.2.0','>=')){ $zaman = new DateTime($deger); $zaman->setTimezone(new DateTimeZone('Europe/Istanbul')); $z["yil"]=$zaman->format('Y'); $z["ay"]=$zaman->format('m'); $z["gun"]=$zaman->format('d'); $z["tam"]=$zaman->format('Y\-m\-d'); $z["damga"]=$zaman->getTimestamp(); }else{ $sifirla = date_default_timezone_get(); date_default_timezone_set('Europe/Istanbul'); $damga=strtotime($deger); date_default_timezone_set($sifirla); $z["yil"]=date('Y',$damga); $z["ay"]=date('m',$damga); $z["gun"]=date('d',$damga); $z["tam"]=date('Y\-m\-d',$damga); $z["damga"]=$damga; } return $z; } function dogumTarihi($kacyilonce,$ad=null,$kimlik=null,$sinif=null){ $once=(date("Y",(time()))-$kacyilonce)."-".date("m-d",(time())); $simdi=date("Y-m-d",time()); return '<input name="'.$ad.'" class="'.$sinif.'" id="'.$kimlik.'"'. ' max="'.$simdi.'" min="'.$once.'" type="date" />'; } ?> <form action="" method="post"> <?php echo dogumTarihi(90,"ddlBirthYear","ddlDogumYil"); ?> <input type="submit" value="Gönder"/> </form> <?php if(isset($_POST["ddlBirthYear"])){ $zaman=zaman($_POST["ddlBirthYear"]) print_r($zaman); //echo $zaman["tam"]; } ?>
Çıktısı
Array ( [yil] => 2015 [ay] => 03 [gun] => 12 [tam] => 2015-03-12 [damga] => 1426114800 )