I want to search all orders in one day during working hours from 08:00 AM till 22:00 pm , i used 2 datetimepickers and select today date but when i search its not show all orders for today , I tried the following code when click search button :
private void BtnSearch_Click(object sender, EventArgs e)
{
string sql = @" SELECT [Order_Payments].[order_id] as 'Acc No.'
,order_vat as 'VAT value'
,vat_orders.[total_amount] as 'Total After VAT'
,[Order_Payments].paid_amount as 'Total Paid'
,[remaining_amount]
,vat_orders.order_date AS 'Order Date'
,Customers.CustName as 'Clinic'
FROM [Order_Payments]
inner join vat_orders on [Order_Payments].order_id = vat_orders.ORDER_ID
inner join Customers on [Order_Payments].custid = Customers.CustId
WHERE 1=1 ";
string condition = "";
string orderby = "";
orderby += " ORDER BY Order_Payments.order_id";
DateTime fromDate;
DateTime toDate;
if (!DateTime.TryParse(dtFromDate.Value.ToString(), out fromDate))
{
System.Windows.Forms.MessageBox.Show("Invalid From Date");
}
else if (!DateTime.TryParse(dtToDate.Value.ToString(), out toDate))
{
System.Windows.Forms.MessageBox.Show("Invalid to Date");
}
else
{
condition += " and vat_orders.order_date between '" + fromDate + "' and '" + toDate + "'";
}
if (textCustId.Text != "")
{
condition += " and Order_Payments.CUSTID ='" + textCustId.Text + "'";
}
DataTable dt = data.fireDatatable(string.Format(sql + condition + orderby));
OrdersDataGridView.DataSource = dt;
OrdersDataGridView.Refresh();
}
How can I update my code and search for example today orders 1/12/2020 08:00 am till 1/12/2020 till 22:00 pm?
Or can I do it with the select statement to select date for today then select from time 00:00 till 22:00 from SQL server?