Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL date column auto fill with current date

Tags:

I have a table where I have a date column. Is there a way for MySQL to auto fill this field whenever I insert a new registry with the current date? Or is this made automatically by default?

P.S.: I'm using PHPMyAdmin

like image 990
Jean Carlos Suárez Marranzini Avatar asked Jan 20 '14 05:01

Jean Carlos Suárez Marranzini


People also ask

How do I set the date to automatically UPDATE in MySQL?

MySQL has some special syntax to do this. You can make the trigger in your create table statement with an with an on update . create table whatever ( ... updated datetime default current_timestamp on update current_timestamp );

How do I auto populate a date in MySQL?

You can use now() with default auto fill and current date and time for this. Later, you can extract the date part using date() function. Let us set the default value with some date.

How do I automatically insert the date in PHPMyAdmin?

To add a date information in PHPMyAdmin you need to log in the PHPMyAdmin interface and then to enter the 'Insert' tab. Then you can choose the appropriate Insert functions for each field using the drop-down list in the functions column.


2 Answers

Although it is an old post, maybe this image will help as it is more explicit: (For phpMyAdmin users)

enter image description here

This configuration sets that field with a value like:

2015-12-11 07:50:47

PS: Note that the timestamp will set the time OF your server!! (i.e. the example above got the time from Pacific Time (07:50:47) but it could have been from a Spanish user at 16:50:47 local time) Keep this in mind.

Also, if you already have a "Created Date" you might need another column that updates the modification date whenever there is an update: You only need to set on update CURRENT TIME STAMP in Attributes Field.

Ready to rock!

enter image description here

like image 165
MLBDG Avatar answered Sep 29 '22 06:09

MLBDG


Set Default to in your mySql query

CURRENT_TIMESTAMP
like image 30
Harshada Chavan Avatar answered Sep 29 '22 08:09

Harshada Chavan