X
X
xenonhammer2020-02-21 21:08:12
PHP
xenonhammer, 2020-02-21 21:08:12

How to add your date in mysql?

Hello!
It is not possible to add a date in MySQL to the DATE format string The
5e501aac47cda355449900.jpeg
request does not cause errors, but also the affected rows - 0

INSERT INTO `oc_product` (`product_id`, date_available) VALUES  (100014, 2000-01-02)  ON DUPLICATE KEY UPDATE `product_id` = VALUES(`product_id`), `date_available` = VALUES(`date_available`);

Tried it like this:
INSERT INTO `oc_product` (`product_id`, date_available) VALUES  (100014, STR_TO_DATE(2000-01-02, %Y,%m,%d))  ON DUPLICATE KEY UPDATE `product_id` = VALUES(`product_id`), `date_available` = VALUES(`date_available`);

And via php :
$date_added_1 = date_create_from_format('d-m-Y', "02-01-2000");
$date_added = date_format($date_added_1, 'Y-m-d ');

What is set by default, but does not accept my values.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-02-21
@xenonhammer

Try reverse programming. Through phpmyadmin you create several records in the table. Export the records from the database to sql code. Read it, see how the query is built, the fields and values ​​are indicated. Trying to run this query with your data. After understanding this, you will understand how to create requests in php and other languages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question