I have following insert query:
INSERT INTO `bid`.`bdate` (`id`, `bid`, `odate`) VALUES (NULL, '1', STR_TO_DATE('02-27-2011 17:58','%Y-%m-%d %H:%i:%s'))
But it is giving me errors. Can some one guide me what Iam doing wrong and how it can be rectified.
Thanks in advance
In a MySQL database, the DATE_FORMAT() function allows you to display date and time data in a changed format. This function takes two arguments. The first is the date/datetime to be reformatted; this can be a date/time/datetime/timestamp column or an expression returning a value in one of these data types.
Example: For converting datetime to format – dd:mm:yyyy, you can use the following query: SELECT DATE_FORMAT('2020-03-15 07:10:56.123', '%d:%m:%Y');
MySQL Date Data Types DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS. YEAR - format YYYY or YY.
You have the date formats in the wrong place. Change your query to:
STR_TO_DATE('02-27-2011 17:58','%m-%d-%Y %H:%i'))
You dont have a place holder for %s.
try this.
INSERT INTO `bid`.`bdate` (`id`, `bid`, `odate`) VALUES (NULL, '1', STR_TO_DATE('02-27-2011 17:58:00','%Y-%m-%d %H:%i:%s'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With