between two times

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frank@sinatra.com

    #1

    between two times

    Hello,

    I am developing a vb.net app and need a little help with determing if the current time is between two times. Kind of like a Shift:
    if current time is between the hours of 0701 and 1500, then user is in Shift one
    else if current time is between the hours of 1501 and 2300, then user is in shift two.
    Ditto for shift three.

    How do I compare the time now() and determine if it falls between two different hours?
    I have tried something along these lines:
    if now.timeofday < 0700 AND now.timeofday < 1500 then
    'Do my bidding
    else...

    This doesn't work as vb.net doesn't allow a greater than/less than comparison on a timespan?

    Any Help would be greatly appreciated.

    Ciao,

    Frankie
    --
    ----------------------------------------------
    Posted with NewsLeecher v3.5 Beta 1
    * Binary Usenet Leeching Made Easy
    * http://www.newsleecher.com/?usenet
    ----------------------------------------------

  • Mike

    #2
    Re: between two times

    Hai,
    why don't you convert the timeofday to seconds by using some
    multiplication like...

    hours * 3600 + mins * 60 + seconds

    And compare the times in seconds..

    Just a thought..if nothing else works!

    Comment

    • Armin Zingler

      #3
      Re: between two times

      "Frank" <frank@sinatra. com> schrieb[color=blue]
      > Hello,
      >
      > I am developing a vb.net app and need a little help with determing
      > if the current time is between two times. Kind of like a Shift: if
      > current time is between the hours of 0701 and 1500, then user is in
      > Shift one
      > else if current time is between the hours of 1501 and 2300, then
      > user is in shift two.
      > Ditto for shift three.
      >
      > How do I compare the time now() and determine if it falls between
      > two different hours?
      > I have tried something along these lines:
      > if now.timeofday < 0700 AND now.timeofday < 1500 then
      > 'Do my bidding
      > else...
      >
      > This doesn't work as vb.net doesn't allow a greater than/less than
      > comparison on a timespan?
      >
      > Any Help would be greatly appreciated.[/color]


      Dim ts As TimeSpan

      ts = Date.Now.TimeOf Day

      If ts.Hours >= 7 AndAlso ts.Minutes <= 15 Then

      - or -

      Dim ts, start, [end] As TimeSpan

      ts = Date.Now.TimeOf Day
      start = New TimeSpan(7, 0, 0)
      [end] = New TimeSpan(15, 0, 0)

      If ts.Ticks >= start.Ticks AndAlso ts.Ticks <= [end].Ticks Then



      Armin

      Comment

      • Gman

        #4
        Re: between two times

        Blue Eyes,

        I guess you're using VS2003 (cos you can use comparison operators in
        VS2005).

        Try using CompareTo. Seems to work for me:

        Dim ts As New TimeSpan(13, 0, 0)
        If DateTimePicker1 .Value.TimeOfDa y.CompareTo(ts) = -1 Then
        Label1.Text = "Less"
        Else
        Label1.Text = "Greater or equal"
        End If


        frank@sinatra.c om wrote:[color=blue]
        > Hello,
        >
        > I am developing a vb.net app and need a little help with determing if the current time is between two times. Kind of like a Shift:
        > if current time is between the hours of 0701 and 1500, then user is in Shift one
        > else if current time is between the hours of 1501 and 2300, then user is in shift two.
        > Ditto for shift three.
        >
        > How do I compare the time now() and determine if it falls between two different hours?
        > I have tried something along these lines:
        > if now.timeofday < 0700 AND now.timeofday < 1500 then
        > 'Do my bidding
        > else...
        >
        > This doesn't work as vb.net doesn't allow a greater than/less than comparison on a timespan?
        >
        > Any Help would be greatly appreciated.
        >
        > Ciao,
        >
        > Frankie[/color]

        Comment

        • frank@sinatra.com

          #5
          Re: between two times

          Armin,

          Thanks for the response. I will give that a try and let you know.

          Thanks again!

          Frankie
          --
          ----------------------------------------------
          Posted with NewsLeecher v3.5 Beta 1
          * Binary Usenet Leeching Made Easy
          * http://www.newsleecher.com/?usenet
          ----------------------------------------------

          Comment

          Working...