Reputation: 8691
Is there a way to insert NOW() in a datetime format - "YYYY-MM-DD HH:MM:SS" in a column of the type "text".
Currently I am using:
INSERT INTO table (mycol) VALUES (DATE(NOW()))
But this inserts the date in the format "YYYY-MM-DD".
Upvotes: 1
Views: 346
Reputation: 9632
Just NOW()
will give you that result, since you're then not casting to DATE
first.
Upvotes: 2
Reputation: 263683
use DATE_FORMAT()
Something like this,
INSERT INTO tablename (sample) VALUES (DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))
or simple
insert into tablename values(now());
Upvotes: 2
Reputation: 37566
Try to use the DATE_FORMAT(date,format)
DATE_FORMAT(NOW(),'%Y-%m-%d %h:%i %p')
Upvotes: 0