Hyder Khan Khosa Hyder Khan Khosa - 3 months ago 7
MySQL Question

Incorrect dateime Value for column 'date' at row 1

I am trying to update my table named as 'permanent_days', in which i have a column, named 'date', as default CURRENT_TIMESTAMP. I having error:



Incorrect dateime Value: '2016-09%' for column 'date' at row 1



This error is coming in following query:

query = "UPDATE permanent_days SET total_days='" +
sum + "' WHERE emp_id_fk='" + ForeignKey +
"' AND date LIKE '" + DateTime.Now.Date.ToString("yyyy-MM") + "%'";
MySqlCommand command = new MySqlCommand(query, connection);
command.ExecuteNonQuery();


I am using phpmyadmin and WPF. Any help could be a great favor

Answer

If you want use like you should convert yot date in string

 "UPDATE permanent_days SET total_days='"  + 
 sum + "' WHERE emp_id_fk='" + ForeignKey + 
 "' AND   DATE_FORMAT(`date` , '%Y-%m') LIKE '" + 
 DateTime.Now.Date.ToString("yyyy-MM") + "%'";