Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

filter date field in objectdatasource

Posted on 2007-12-13
8
Medium Priority
?
1,436 Views
Last Modified: 2012-08-13
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!
0
Comment
Question by:arcross
  • 5
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20464069
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
 
LVL 8

Author Comment

by:arcross
ID: 20464206
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
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20464237
Dim dt As Date = Date.Now
Me.ods_ItemsList.FilterExpression = "dateposted > # " & dt & " #"
I added spaces around the #'s
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20464245
If that doesn't work then try
Dim dt As DateTime = DateTime.Now
Me.ods_ItemsList.FilterExpression = "dateposted > # " & dt & " #"
0
 
LVL 14

Expert Comment

by:Dustin Hopkins
ID: 20464282
Also have you tried it with a hard date like...
Me.ods_ItemsList.FilterExpression = "dateposted > #12/13/2007#"
0
 
LVL 8

Author Comment

by:arcross
ID: 20464367
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
 
LVL 8

Author Comment

by:arcross
ID: 20464390
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
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 2000 total points
ID: 20464438
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question