2

Can any one specify, how can be set default value for Date and Datetime field in Mysql from phpmyadmin interface?

Sumesh TG
  • 440
  • 1
  • 4
  • 15

2 Answers2

3

Use CURRENT_TIMESTAMP constant

also check this link

Community
  • 1
  • 1
mrsrinivas
  • 34,112
  • 13
  • 125
  • 125
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
  • 1
    No, 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