Reputation: 95
I am trying to insert a date & time value into table
Here is my query
Insert INTO tableName(attDate) VALUES ("22-Sep-2019 19:28:10")
Here attDate column is having type datetime, i have tried above query using DATE_FORMAT function but no luck. And also i am not suppose to use the date value in a variable. Will anybody guide me to proper way.
Upvotes: 0
Views: 1845
Reputation: 28834
You can use Str_To_Date()
function to convert a datetime value to MySQL datetime format (YYYY-MM-DD HH:MM:SS)
Insert INTO tableName(attDate)
VALUES (STR_TO_DATE('22-Sep-2019 19:28:10', '%d-%b-%Y %T'))
Details:
%d
Day of the month as a numeric value (01 to 31)%b
Abbreviated month name (Jan to Dec)%Y
Year as a numeric, 4-digit value%T
Time in 24 hour format (hh:mm:ss)Upvotes: 3