user2699428
user2699428

Reputation:

How change date type in mysql

I want to keep column default value as current date in mysql.what should be its type.i tryied date and timestamp but not allowed.can anybody say me what should be appropriate data type?

Morely i want to keep default value as current date.how it can be done.At begining default value was set

Upvotes: 0

Views: 75

Answers (3)

rony36
rony36

Reputation: 3339

Try:

ALTER TABLE tablename MODIFY columnname  TIMESTAMP;

More details here and here.

Updated

Simply:

ALTER TABLE tablename CHANGE columnnane TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP'

More details.

Upvotes: 1

Lucifer
Lucifer

Reputation: 516

ALTER TABLE tablename CHANGE fieldname fieldname datatype( 11) NOT NULL

Upvotes: 0

Vinayak
Vinayak

Reputation: 436

Try this :

ALTER TABLE MyTable ADD COLUMN realdate DATE;
UPDATE MyTable SET realdate = STR_TO_DATE(textdate, '%d/%m/%y');

Upvotes: 4

Related Questions