I Really need your help guys , i created a table in sql and i displayed it in a datagridview that contains product and date(it's a datatime variable),but what i want is filter products by current date without time (i want products that refers just to the current date),here is the codeenter image description here
and here is the result , it does filter anything enter image description here
CodePudding user response:
If you want to filter by date and not time where there's no function to get just a date value from the data, the simplest option is to use a range. Assuming that you have a DataTable
, you should bind it to your DataGridView
via a BindingSource
, which you can add to the form in the designer. You could then filter based on the current date like so:
myBindingSource.Filter = $"DateTimeColumn >= #{DateTime.Now:M/dd/yyyy}# AND DateTimeColumn < #{DateTime.Now.AddDays(1):M/dd/yyyy}#"
That will produce a string
like "DateTimeColumn >= #10/02/2022# AND DateTimeColumn < #10/03/2022#"
, so match any time with today's date.