I have a table and theDate field is structured as INT (32) .
Writing PHP scripts I would like to use mySQL PDO to insert the unix timestamp as an integer into theDate INT table field. What is the best way to do this? And what is the most efficient size for my theDate field? 8, 16, 32?
code:
$theDate = now(); // this returns a 0 in theDate mySQL field
$stmt = $db->prepare("INSERT INTO countries(name, capital, language, theDate) VALUES (:country, :capital, :language, :theDate)");
$stmt->bindParam(':country', $country, PDO::PARAM_STR, 100);
$stmt->bindParam(':capital', $capital, PDO::PARAM_STR, 100);
$stmt->bindParam(':language', $language, PDO::PARAM_STR, 100);
$stmt->bindParam(':theDate', $theDate );
if($stmt->execute()) {
echo '1 row has been inserted';
}
I have googled this and searched this site.. can't find a good answer
thanks
datetimefield instead; it makes life much easier when you want to retrieve anything by date... though, in this case, it looks like you might want atimestampfield... I can't see any logical reason to store the date on a country table except to record the time at which the record was last updated.DATETIMEfield, and using the native format gives you access to tons of additional functions as well as making them human readable. Be sure to insert these times as UTC to avoid time-zone issues. You can do any time-zone conversion in PHP when displaying these values if that's relevant.