I want to get data between two dates.I am using a MySql database with my C# winforms. At the time of inserting the dates I converted the date to dd-MM-yyyy
and saved these dates in the database having column of type varchar. Now I want to fetch results between two dates here is my code:
string dateFrom = dtp_dfrom.Value.ToString("dd-MM-yyyy");
string dateTo = dtp_dto.Value.ToString("dd-MM-yyyy");
//MessageBox.Show(dateFrom+" "+dateTo);
conn = new MySqlConnection(myconstring);
DataTable dt = new DataTable();
MySqlDataAdapter sda = new MySqlDataAdapter("SELECT trans_date, product_type AS Item, product_quantity, amount, SUM( product_quantity ) AS Qty, SUM( amount ) AS 'Total Price' FROM main_table WHERE trans_date BETWEEN '"+dateFrom+"' AND '"+dateTo+"' GROUP BY product_type", conn);
sda.Fill(dt);
Now the problem is I am not getting the date as required.Anybody can help me out. I am very new to dates formats. Thanks in advance.