Dzhuneyt
Dzhuneyt

Reputation: 8691

Datetime Equivalent of Date(Now()) for Insert

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

Answers (3)

slugonamission
slugonamission

Reputation: 9632

Just NOW() will give you that result, since you're then not casting to DATE first.

Upvotes: 2

John Woo
John Woo

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());

SQLFIDDLE Demo

Upvotes: 2

CloudyMarble
CloudyMarble

Reputation: 37566

Try to use the DATE_FORMAT(date,format)

DATE_FORMAT(NOW(),'%Y-%m-%d %h:%i %p')

Upvotes: 0

Related Questions