Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto TimeStamp new entry to DB (phpMyAdmin)

Tags:

If I want each new entry into my db to be automatically timestamped, would I set the Field Type to "timestamp" and have the Default value set to "CURRENT_TIMESTAMP"?

Is this the correct method?

like image 636
BigMike Avatar asked Sep 01 '10 06:09

BigMike


People also ask

What is current TIMESTAMP in PHPMyAdmin?

MySQL CURRENT_TIMESTAMP() Function The CURRENT_TIMESTAMP() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).

How do I add a TIMESTAMP to a date in MySQL?

The simplest method to insert the current date and time in MySQL is to use the now() function. Once you call the function, it returns the current date and time in the system's configured time zone as a string. The value returned from the now() function is YYYY-MM-DD for the date and HH-MM-SS-UU for the time record.


1 Answers

That is correct. In SQL code that would be:

CREATE TABLE `table` (     ...     `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,      ... ) 
like image 87
BoltClock Avatar answered Oct 29 '22 23:10

BoltClock