Can any one specify, how can be set default value for Date and Datetime field in Mysql from phpmyadmin interface?
Asked
Active
Viewed 1.4k times
2
-
Which version of phpMyAdmin? Also, [dba.SE](http://dba.stackexchange.com) is a better fit for this question. – outis Jul 27 '12 at 05:01
-
You can check here http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html – Vishwanath Dalvi Jul 27 '12 at 05:02
2 Answers
3
Use CURRENT_TIMESTAMP
constant
also check this link

Community
- 1
- 1

mrsrinivas
- 34,112
- 13
- 125
- 125
-
3Thank you. CURRENT_TIMESTAMP is only for 'timestamp' type, not for 'date' & 'datetime' type. – Sumesh TG Jul 27 '12 at 06:18
-
@SumeshTG: FYI - storing date and time, as it is in database not suggestible. – mrsrinivas Jun 21 '14 at 08:08
1
You can specify exact default values for DATE and DATETIME fields, e.g. -
CREATE TABLE table1(
id INT(11) NOT NULL,
date_column DATE DEFAULT '2012-01-01',
datetime_column DATETIME DEFAULT '2010-05-05 10:30:00',
PRIMARY KEY (id)
);
INSERT INTO table1 (id) VALUES (1);
SELECT * FROM table1;
+----+-------------+---------------------+
| id | date_column | datetime_column |
+----+-------------+---------------------+
| 1 | 2012-01-01 | 2010-05-05 10:30:00 |
+----+-------------+---------------------+
If you want to use function to define DEFAULT values, then you can create a trigger.

Devart
- 119,203
- 23
- 166
- 186
-
Thank you. Can you specify how to set default 'date' as 'current date' and 'datetime' as 'current date time', without using a trigger?. – Sumesh TG Jul 27 '12 at 07:36
-
1No, there is no good ways. Unfortunately MySQL doesn't allow using functions to set default values for DATE, DATETIME fields. You also may implement this logic in a stored procedure, and use it to add new records. – Devart Jul 27 '12 at 07:46