I have a table in a SqlServer database which contains a couple of
DateTime fields, 'StartTime' and 'EndTime'. These fields are only used
to store time, not date. Since I don't specify any date information,
all the records have '1/1/1900' for their date.

Once I've loaded all the records into a DataView, I would like to be
able to filter the records by StartTime and EndTime. The time value I
want to filter on is stored in a TimeSpan variable. Apparently, you
can't compare DateTime values directly to TimeSpan values in a
RowFilter, so I wind up doing something like this:

DateTime date = new DateTime(time.Ticks);
DataView1.RowFilter = "(date > StartTime) AND (date < EndTime)";

Unfortunately, the .NET DateTime class starts at '1/1/0001'. So my
filter looks something like this:

"('1/1/0001 6:00AM' > '1/1/1900 6:00AM') AND ('1/1/0001 8:00PM' >
'1/1/1900 8:00PM)"

Which never returns any results, of course. What I want to do is JUST
compare two time values. Is there an easy way to do this?

TIA,
Gabe

Re: RowFilter on Time values by William

William
Tue Jun 01 22:00:44 CDT 2004

Gabe:

I don't think this is ever going to work unless EndTime and StartTime are
column names in the datatable. What I guess I'm having trouble with is how
can the same variable "date" have a value of '1/1/0001 6:00AM' in one part
of the equation and '1/1/0001 8:00PM' in the next when there's no
assignment? Also, just as a matter of style, I'd reconsider using Date as a
variable name...lot's of potential for trouble there. Anyway, I think after
looking at it again I see what you mean though --- never mind my first
observations. In this case, why not do a add 1899 years to your 'date'
variable.. then they'll match?

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"Gabe Moothart" <gabe@imaginesystems.net> wrote in message
news:e63pjnDSEHA.916@TK2MSFTNGP12.phx.gbl...
> I have a table in a SqlServer database which contains a couple of
> DateTime fields, 'StartTime' and 'EndTime'. These fields are only used
> to store time, not date. Since I don't specify any date information,
> all the records have '1/1/1900' for their date.
>
> Once I've loaded all the records into a DataView, I would like to be
> able to filter the records by StartTime and EndTime. The time value I
> want to filter on is stored in a TimeSpan variable. Apparently, you
> can't compare DateTime values directly to TimeSpan values in a
> RowFilter, so I wind up doing something like this:
>
> DateTime date = new DateTime(time.Ticks);
> DataView1.RowFilter = "(date > StartTime) AND (date < EndTime)";
>
> Unfortunately, the .NET DateTime class starts at '1/1/0001'. So my
> filter looks something like this:
>
> "('1/1/0001 6:00AM' > '1/1/1900 6:00AM') AND ('1/1/0001 8:00PM' >
> '1/1/1900 8:00PM)"
>
> Which never returns any results, of course. What I want to do is JUST
> compare two time values. Is there an easy way to do this?
>
> TIA,
> Gabe



Re: RowFilter on Time values by Tor

Tor
Wed Jun 02 06:59:46 CDT 2004

Hi
Welll you could just use something like the following code:
System.DateTime myStartDate=System.DateTime.Parse("1/1/1900");
System.DateTime myEndDate=System.DateTime.Parse("1/1/1900");
Add the required amount of hours,minutes and seconds to each. Then do your
comparison.
how this: "DataView1.RowFilter = "(date > StartTime) AND (date < EndTime)";"
works the way you say it does
seems impossible to me.

Tor Arne Gjelhus

"Gabe Moothart" <gabe@imaginesystems.net> wrote in message
news:e63pjnDSEHA.916@TK2MSFTNGP12.phx.gbl...
> I have a table in a SqlServer database which contains a couple of
> DateTime fields, 'StartTime' and 'EndTime'. These fields are only used
> to store time, not date. Since I don't specify any date information,
> all the records have '1/1/1900' for their date.
>
> Once I've loaded all the records into a DataView, I would like to be
> able to filter the records by StartTime and EndTime. The time value I
> want to filter on is stored in a TimeSpan variable. Apparently, you
> can't compare DateTime values directly to TimeSpan values in a
> RowFilter, so I wind up doing something like this:
>
> DateTime date = new DateTime(time.Ticks);
> DataView1.RowFilter = "(date > StartTime) AND (date < EndTime)";
>
> Unfortunately, the .NET DateTime class starts at '1/1/0001'. So my
> filter looks something like this:
>
> "('1/1/0001 6:00AM' > '1/1/1900 6:00AM') AND ('1/1/0001 8:00PM' >
> '1/1/1900 8:00PM)"
>
> Which never returns any results, of course. What I want to do is JUST
> compare two time values. Is there an easy way to do this?
>
> TIA,
> Gabe



Re: RowFilter on Time values by Miha

Miha
Wed Jun 02 07:33:39 CDT 2004

Hi Gabe,

You also have problems with date settings on your computer :-)
See the post date....
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Gabe Moothart" <gabe@imaginesystems.net> wrote in message
news:e63pjnDSEHA.916@TK2MSFTNGP12.phx.gbl...
> I have a table in a SqlServer database which contains a couple of
> DateTime fields, 'StartTime' and 'EndTime'. These fields are only used
> to store time, not date. Since I don't specify any date information,
> all the records have '1/1/1900' for their date.
>
> Once I've loaded all the records into a DataView, I would like to be
> able to filter the records by StartTime and EndTime. The time value I
> want to filter on is stored in a TimeSpan variable. Apparently, you
> can't compare DateTime values directly to TimeSpan values in a
> RowFilter, so I wind up doing something like this:
>
> DateTime date = new DateTime(time.Ticks);
> DataView1.RowFilter = "(date > StartTime) AND (date < EndTime)";
>
> Unfortunately, the .NET DateTime class starts at '1/1/0001'. So my
> filter looks something like this:
>
> "('1/1/0001 6:00AM' > '1/1/1900 6:00AM') AND ('1/1/0001 8:00PM' >
> '1/1/1900 8:00PM)"
>
> Which never returns any results, of course. What I want to do is JUST
> compare two time values. Is there an easy way to do this?
>
> TIA,
> Gabe



Re: RowFilter on Time values by Gabe

Gabe
Wed Jun 02 10:59:55 CDT 2004

William Ryan eMVP wrote:
> I don't think this is ever going to work unless EndTime and StartTime are
> column names in the datatable. What I guess I'm having trouble with is how
> can the same variable "date" have a value of '1/1/0001 6:00AM' in one part
> of the equation and '1/1/0001 8:00PM' in the next when there's no
> assignment?
That was my mistake. I didn't give my actual code, just a simplified
version of it, and I got it a little mixed up.

Also, just as a matter of style, I'd reconsider using Date as a
> variable name...lot's of potential for trouble there. Anyway, I think after
> looking at it again I see what you mean though --- never mind my first
> observations. In this case, why not do a add 1899 years to your 'date'
> variable.. then they'll match?

I was hoping there was a way to just compare the time portion of each
value (adding the date offset feels a little too
implementation-dependent), but it looks like I don't have a choice.

thanks,
Gabe

RowFilter on Time values by Cor

Cor
Wed Jun 02 14:11:44 CDT 2004