Wednesday, April 30, 2014

PHP time and SQL time

In SQL there is the option to use datetime as a format. However if you insert data in, it is hard to format it correctly from PHP on the first try. So it is better to use TIMESTAMP for your SQL column and use now() to insert the correct time.

mysql_query("
            INSERT INTO users (first, last, timenow)
            VALUES ('$first', '$last', now())");