Results 1 to 4 of 4

Thread: in between date

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Resolved in between date

    hello!
    i have these data:
    date item
    08/10/2007 07:34 AM data1
    08/10/2007 07:35 AM data2
    08/10/2007 07:36 AM data2
    08/10/2007 09:01 AM data3

    how would i find the data in date between 08/10/2007 07:33 AM to 08/10/2007 07:37 AM?

    i try this but it will find all including the 09:01 AM

    Code:
    if (DateTime.Compare(DateTime.Now.AddMinutes(-20),DateTime.Now)<0)
    *****************
    VB6,PHP,VS 2005

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: in between date

    Unless I'm misunderstanding the question, I'm not sure what that last line has to do with finding the DateTimes in between your start and stop. You could just put your DateTimes in a list and just loop through it and check if each one is between your start and stop DateTimes.

    Assuming your have your data in a list called times and you've created a start and stop DateTime.
    c# Code:
    1. foreach (DateTime dt in times)
    2. {
    3.     if (dt > startTime && dt < stopTime)
    4.     {
    5.         MessageBox.Show(dt.ToString());
    6.     }
    7. }

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Location
    /root/usr/local/bin
    Posts
    476

    Re: in between date

    if (Convert.ToDateTime(dateValue) > DateTime.Now.AddMinutes(-20) && Convert.ToDateTime(dateValue) < DateTime.Now)
    {
    //add to the datagrid and
    //save to the database
    }

    tnx you gave me an idea how to solve the problem...
    *****************
    VB6,PHP,VS 2005

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: in between date

    Are you querying a database for the infor? If so you would use a between construct in the SQL statement (or a > < constraint) in the WHERE cluase.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width