|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
between two timesI 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 ----------------------------------------------
Show quote
Hide quote
"Frank" <fr***@sinatra.com> schrieb Dim ts As TimeSpan> 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. 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 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 ---------------------------------------------- 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! 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
Adding button programatically - NON-FUNCTIONAL!!
Checking for new versions in a setup project Garbage collection and callbacks from unmanaged code. timer Exception Error When Calling Procedure Multiple Times Can a console VB.NET prog return a value to caller? Help with strings. Array.Sort Error on Graphics CompositingMode.SourceCopy Numeric Variables |
|||||||||||||||||||||||