If you do not specify a timestamp, the current date and time will be used (as shown in the examples above). As you ve seen, you can generally just use the SQL NOW function to insert into a SQL timestamp fiel but if that doesn t work for some reason, you can also create a timestamp field in the proper format using just PHP and the date function. The mktime function returns the Unix timestamp for a date. The typical mysql date format is date( Y-m-d H:i:s Check the manual page for what other letters represent. Now, we are going to see about PHP timestamp functions.
Back to top PHP SQL Timestamp inserts.
You want to do the opposite, which is date. Create a Date With PHP mktime The optional timestamp parameter in the date function specifies a timestamp. This is perhaps the easiest way I have found to pull the PHP usable UNIX Datestamp from my mySQL datestamp stored in the tables. Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.
In 64-bit systems this function will still work as intended.