Search code examples
c#datedatetimefilterbindingsource

c# bindingsource filter by datetime


The problem I'm having is that the filter will not accept the time part of a datetime.

For clarity,

This works.

" AND NextWorkDate <= #" + DateTime.Now.AddDays(1).ToString("dd.M.yyyy") + "#"

This doesnt work.

" AND NextWorkDate <= #" + DateTime.Now.AddDays(1).ToString("dd.M.yyyy H:mm:ss") + "#"

Whenever I try to include the time aspect of the datetime, the filter just doesnt work, it returns no rows.

I've tried it a thousand different ways and I really cant figure out why it won't take the damn time.

The datasource column that the filter is comparing to is a datetime with the format dd.M.yyyy H:mm:ss.

The database column is formatted completely differently, as yyyy-mm-dd hh:mm:ss:fff

Could this be causing some problem along the line? I think it isn't because the filter is applied to the datasource, not the database.


Solution

  • Solved.

    The problem was my own foolishness. There was another class filtering the string before it went to the bindingsource.