Results 1 to 3 of 3

Thread: Check time range.

  1. #1

    Thread Starter
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    Check time range.

    Hi,

    I'm having a tuff time trying to check if the current time is within a certain range. This is probably very simple, but I can't figure it out.
    The AM and PM are not being taken into account...


    Code:
            If (Date.Now.ToShortTimeString > "3:00AM" And Date.Now.ToShortTimeString < "4:30AM") Then
                Response.Redirect("test.aspx")
            End If
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Check time range.

    Something like this:

    Code:
            Dim dtn As DateTime = Now
            Dim ts3AM As TimeSpan = New TimeSpan(3, 0, 0)
            Dim ts430AM As TimeSpan = New TimeSpan(4, 30, 0)
            If (dtn.TimeOfDay > ts3AM And dtn.TimeOfDay < ts430AM) Then
                MessageBox.Show("Between 3 and 430")
            End If
    Note that I store Now in a variable, that way it will be the same for both evaluations.

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Check time range.

    Code:
            'ON THE SAME DAY!
            Dim stDT As DateTime = DateTime.Parse("3:00:00 AM") 'start
            Dim eDT As DateTime = DateTime.Parse("4:30:00 AM") 'end
            If DateTime.Now.CompareTo(stDT) >= 0 AndAlso DateTime.Now.CompareTo(eDT) <= 0 Then
                Stop
            End If
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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