Ranges of time logic?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin

    Ranges of time logic?

    I'm trying to write a routine that checks records to see if they are
    between a range of times and days.

    For example, someone might want records dated from August 2-August 5
    from 5:00am to 10:50am. It should only return records from the 2nd to
    the 5th, and from 5:00am to 10:50am (nothing before or after those
    times).

    I have been trying to do this using an hour and a minute integer but I
    haven't been able to solve the logic.

    Is there an easier way to accomplish this? I can't find much about it
    using DateTime either.

    *** Sent via Developersdex http://www.developersdex.com ***
  • Jeroen Mostert

    #2
    Re: Ranges of time logic?

    Justin wrote:
    I'm trying to write a routine that checks records to see if they are
    between a range of times and days.
    >
    For example, someone might want records dated from August 2-August 5
    from 5:00am to 10:50am. It should only return records from the 2nd to
    the 5th, and from 5:00am to 10:50am (nothing before or after those
    times).
    Something like

    d.Date >= new DateTime(2008, 8, 2) && d.Date <= new DateTime(2008, 8, 5) &&
    d.TimeOfDay >= new TimeSpan(5, 0, 0) && d.TimeOfDay <= new TimeSpan(10, 50, 0)

    if I understand you correctly.

    --
    J.

    Comment

    • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

      #3
      RE: Ranges of time logic?

      Try something like this, it will need to be adapted to suit your exact
      situation but this should work.


      DateTime EarliestDateTim e = new DateTime(2008,8 ,2,5,0,0);
      DateTime LatestDateTime = new DateTime(2008,8 ,5,10,50,0);

      List<DateTimeda tetimes;
      List<DateTimere sults= datetimes.FindA ll(new
      Predicate<DateT ime>(delegate(D ateTime theDate)
      {
      return theDate >= EarliestDateTim e && theDate <= LatestDateTime &&
      theDate.TimeOfD ay >= EarliestDateTim e.TimeOfDay && theDate.TimeOfD ay <=
      LatestDateTime. TimeOfDay;
      }));


      --
      Ciaran O''Donnell
      try{ Life(); } catch (TooDifficultException) { throw Toys(); }



      "Justin" wrote:
      I'm trying to write a routine that checks records to see if they are
      between a range of times and days.
      >
      For example, someone might want records dated from August 2-August 5
      from 5:00am to 10:50am. It should only return records from the 2nd to
      the 5th, and from 5:00am to 10:50am (nothing before or after those
      times).
      >
      I have been trying to do this using an hour and a minute integer but I
      haven't been able to solve the logic.
      >
      Is there an easier way to accomplish this? I can't find much about it
      using DateTime either.
      >
      *** Sent via Developersdex http://www.developersdex.com ***
      >

      Comment

      Working...