?
Solved

Filter on Time in date time type field.

Posted on 2012-04-03
9
Medium Priority
?
332 Views
Last Modified: 2012-06-03
Hi
Nilesh here,
I have a dataset with a date time type filed. I want to filter that date time field. I want to do filter by time not whole date.

Suppose there is a date time like "2012-04-04 10:34:21", then I want to filter on only time like datetimefiled>="10:34:21".

So how can I solve this?
Thanks in advance.
0
Comment
Question by:avacaralife
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 6

Expert Comment

by:kswathi
ID: 37804626
you can use Dataview for  the dataset

DataView dv = new DataView(yourdataset);
dv.RowFilter="YourDatecolumn >= #yourdate#";

Also you can refer the below link:
http://www.csharp-examples.net/dataview-rowfilter/
0
 

Author Comment

by:avacaralife
ID: 37804632
Thanks dear kswathi,

I do not want to filter on date, I want to filter on only time like dateTimeFiled>="10:30" like that. No need to check date. its need to check only time.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 37804661
You can use LINQ for it .

Example:
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("ID",typeof(int)));
            dt.Columns.Add(new DataColumn("Date",typeof(DateTime)));

            DataRow dr = dt.NewRow();
            dr["ID"] = 1;
            dr["Date"] = new DateTime(2012,4,4,10,10,10);
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["ID"] = 1;
            dr["Date"] = new DateTime(2012,4,4,11,11,11);
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["ID"] = 1;
            dr["Date"] = new DateTime(2012,4,4,12,12,12);
            dt.Rows.Add(dr);

            DateTime ToCompare= new DateTime(2012,4,4,10,15,30);

            DataRow[] rows = dt.Rows.Cast<DataRow>().Where(x => (int.Parse(((DateTime)x["Date"]).ToString("HH")) * 3600 +
                                                                 int.Parse(((DateTime)x["Date"]).ToString("mm")) * 60 +
                                                                 int.Parse(((DateTime)x["Date"]).ToString("ss")))
                                                                 >= (ToCompare.Hour*3600 + ToCompare.Minute*60+ToCompare.Second)).ToArray();
0
Independent Software Vendors: 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!

 

Expert Comment

by:ramgunti
ID: 37804666
Dear friend,

  Do u want to filter the data on a specific day on a specific time or what?
0
 

Author Comment

by:avacaralife
ID: 37804669
Dear Sir,
Yes I want to filter data on specific time.
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 37804688
Example I've provided will search all the rows with the time that are after the one I've provided (after 10:15:30). You'll need to convert it to seconds to compare the values. You can't just compare the string "11:11:11" >= "10:15:30"
0
 

Author Comment

by:avacaralife
ID: 37804694
Ok Thanks sir,

Now I am trying it in sql server.
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38041430
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

766 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