Solved

Filter on Time in date time type field.

Posted on 2012-04-03
9
327 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
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 500 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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