Avatar of lossiemouth
lossiemouth
 asked on

dataview rowfilter by date

Hi,
I have a dataview with a DATE column which is in Date format (not string)

I have a datetimepicker.

The user selects a date from the datetimepicker.
I want to rowfilter the dataview, so that all rows which have a Date, later than
the selected datetimepicker date, are displayed.

something like:
 myDate = DateTimePicker1.Value.Date
       myView.RowFilter = ("Date <=   myDate ")

The above does not work. I have tried various combinations of the above but no joy.

Any help is greatly appreciated.

Lossie  
DatabasesVisual Basic Classic

Avatar of undefined
Last Comment
pradyahuja

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
pradyahuja

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
lossiemouth

ASKER
Thank you. It now filters but I have a problem with date formats.

The Dataview is taken from a XML table. The date format is YYYY-MM-DD
The datetimepicker has a format of MM/DD/YYYY

This is causing problems with the filter.

Is there a way to change one of the formats, so that they match?

Lossie
pradyahuja

myDate =myDate .ToString("MM/DD/YYYY")
lossiemouth

ASKER
I get exception

string is not a valid datetime

Lossie
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
pradyahuja

myDate =Convert.ToDateTime(myDate).ToString("dd/MM/yyyy")
lossiemouth

ASKER
Thank you pradyahuja
I get the same exception.

Perhaps I should ask this as a seperate question?
pradyahuja

when this code executes, can u see whats the value of myDate?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
lossiemouth

ASKER
If I select 16 Feb 2010 on the datetimepicker
This is the exception

System.InvalidCastException was unhandled
  Message="Conversion from string "02/16/2010" to type 'Date' is not valid."
pradyahuja

works fine on my machine.
try changing date to 02/02/2010
lossiemouth

ASKER
The dataview Date column format is yyyy-mm-dd
So, I try to change the datetimepicker format to match the dataview
myDate = DateTimePicker1.Value.Date
myDate = myDate.ToString("yyyy-MM-dd")

When I run this code, myDate = #2/2/2010#
I was hoping for 2010-02-02

However, I could be wrong, but I don't think it would work anyway. because I am now trying to
use a string to rowfilter a Date column.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
pradyahuja

oh ok...