How to use DataView.RowFilter when the property is DateOnly

LXY 20 Reputation points
2024-08-21T18:11:52.12+00:00

Does the RowFilter support DateOnly type property?

How to filter DataRow by DateOnly 's value?

Developer technologies | .NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2024-08-22T02:16:59.41+00:00

    Hi @LXY ,

    DataView.RowFilter does not directly support the DateOnly type since RowFilter works with string representations of data types like DateTime.

    Convert both the column values and DateOnly to strings and then compare.

    Dim filterDate As DateOnly = DateOnly.FromDateTime(New DateTime(2024, 8, 22))
    myView.RowFilter = $"CONVERT([YourDateColumn], 'System.String') LIKE '{filterDate}%'"
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2024-08-21T18:35:47.7866667+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.