Incorrect datetime value in MySQL

2

I was trying to register using a query in c # the datetime.now in a MySQL database

What I do in c # is:

cmd.CommandText = "INSERT INTO cola_llamadas(fecha,queueName,cola)" +
                  "VALUES(DATE_FORMAT('"+DateTime.Now+"', '%m/%d/%Y %H:%i'),'XXXX'," + Convert.ToInt32(subaux) +")";
cmd.ExecuteNonQuery();

The string of the query is apparently fine:

"INSERT INTO cola_llamadas(fecha,queueName,cola) VALUES(DATE_FORMAT('24/10/2017 16:35:03', '%m/%d/%Y %H:%i'),'XXXX',2)"

The problem is that I want to put it in a database with the format of

dd/mm/yyyy HH24:MI:SS < --- I hope to explain myself with this. How can I convert the string? In SQL I would do it easily with To_Date, but in MySQL?

This is the error that returns me exactly:

#1292 - incorrect datetime value: '24/10/2017' 16:35:03'

It must be something very simple, but right now I do not fall and it's the first time I use MySQL as such.

    
asked by Aritzbn 24.10.2017 в 16:48
source

1 answer

1

The insert should be like this

"INSERT INTO cola_llamadas(fecha,queueName,cola) VALUES('24/10/2017 16:35:03','XXXX',2)"

and it would work perfect. Now in C # you can do the following. link I would also advise you to use EntityFramework since it facilitates much the handling of data and queries to the db link

cmd.CommandText = "INSERT INTO cola_llamadas(fecha,queueName,cola)" +
                  "VALUES("+DateTime.Now.ToString("format")+"','XXXX'," + Convert.ToInt32(subaux) +")";
cmd.ExecuteNonQuery();
    
answered by 24.10.2017 / 17:49
source