Solved

Filter on Time in date time type field.

Posted on 2012-04-03
9
329 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 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
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!

 

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

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

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 44
SSRS Deployment problem 5 96
reading excel file in .net 2 32
ASP.NET data base connection 35 39
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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