Home All Groups Group Topic Archive Search About
Author
8 Mar 2006 4:08 PM
frank@sinatra.com
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
----------------------------------------------

Author
8 Mar 2006 5:18 PM
Armin Zingler
Show quote Hide quote
"Frank" <fr***@sinatra.com> schrieb
> 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.


   Dim ts As TimeSpan

   ts = Date.Now.TimeOfDay

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

- or -

   Dim ts, start, [end] As TimeSpan

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

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



Armin
Author
8 Mar 2006 7:47 PM
frank@sinatra.com
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
----------------------------------------------
Author
8 Mar 2006 5:36 PM
Mike
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!
Author
8 Mar 2006 6:06 PM
Gman
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.TimeOfDay.CompareTo(ts) = -1 Then
    Label1.Text = "Less"
Else
    Label1.Text = "Greater or equal"
End If


fr***@sinatra.com wrote:
Show quoteHide quote
> 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