This should be an easy one but I just can\'t find the answer.
I have an input field in which the user enters his birthay date (DD.MM.YYYY) and with strtotime() I ins
You should use MySQL DATETIME, calculate in sql query . use php date() function to convert to mysql DATETIME when you save into database
You should use the DateTime object when handling dates and times in PHP. It is very flexible when parsing date formats, it can calculate the difference between two dates and it has no 1970 or 2038 problem.
You must use DateTime object, You can see one sample code here:
<?php
$date = new DateTime("1960-05-06");
$timestamp = $date->getTimestamp();
echo $timestamp; //-304707600
echo "\n";
$date = new DateTime();
$date->setTimestamp($timestamp);
$birthday = $date->format("Y-m-d");
echo $birthday; //1960-05-06
echo "\n";
echo date("Y") - $date->format("Y"); //55 years old for now (2015)
?>
Output:
-304732800
1960-05-06
55
Online test here: https://ideone.com/sKjBWS