filter date field in objectdatasource

im trying to filter an objectdatasource on a date field but with no success so far.
it throws me an error saying :String was not recognized as a valid DateTime.

this is what im doing:
  Dim dt As String = Date.Now.ToShortDateString
  Me.ods_ItemsList.FilterExpression = "dateposted > #" & dt & "#"

help!
TIA!
LVL 8
arcrossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin HopkinsSenior Web DeveloperCommented:
What happens if you feed it the full datetime instead of the short version? or if you send it as a datetime object instead of a string.
0
arcrossAuthor Commented:
with this code throws me this error:
Dim dt As Date = Date.Now
Me.ods_ItemsList.FilterExpression = "dateposted > #" & dt & "#"

"String was not recognized as a valid DateTime"

and this, gives me the following error: (notice i removed #)
 Dim dt As Date = Date.Now
 Me.ods_ItemsList.FilterExpression = "dateposted > " & dt

"Syntax error: Missing operand after '13' operator"
the first record of the grid has the value on the date field: 27/12/2007 13:41:36
0
Dustin HopkinsSenior Web DeveloperCommented:
Dim dt As Date = Date.Now
Me.ods_ItemsList.FilterExpression = "dateposted > # " & dt & " #"
I added spaces around the #'s
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Dustin HopkinsSenior Web DeveloperCommented:
If that doesn't work then try
Dim dt As DateTime = DateTime.Now
Me.ods_ItemsList.FilterExpression = "dateposted > # " & dt & " #"
0
Dustin HopkinsSenior Web DeveloperCommented:
Also have you tried it with a hard date like...
Me.ods_ItemsList.FilterExpression = "dateposted > #12/13/2007#"
0
arcrossAuthor Commented:
i tried hard coded and it errored again.
 Me.ods_ItemsList.FilterExpression = "dateposted < #13/12/2007#"

then i tried using the american format like you said
 Me.ods_ItemsList.FilterExpression = "dateposted < #12/13/2007#"

and it was fine.

how can i make sure i filter with my regional settings
0
arcrossAuthor Commented:
this seems to work fine

 Me.ods_ItemsList.FilterExpression = "finishdate < #" & Date.Now.ToString("MM/dd/yyyy") & "#"

even in my grid it is showing dd/MM/yyyy format
0
Dustin HopkinsSenior Web DeveloperCommented:
Inorder to use your regional settings with dates you must use the parse method and system.globalization. Here is a link to Microsoft on using globalization to parse dates

http://msdn2.microsoft.com/en-us/library/2h3syy57(VS.80).aspx

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.