Time Problem

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

    Time Problem

    What I thought would be pretty easy has turned out not to be.

    I have three variables. Actiontime is formatted as 08/11/2004 11:03PM

    Actiontime
    JobStreamStart (11:00:00PM)
    JobStreamEnd (2:00:00AM)

    If (Format(CDate(A ctionTime), "t") >= JobStreamStart AND
    (Format(CDate(A ctionTime), "t") < jobstreamend Then

    Do these actions

    End If

    Does not work. I am having a problem after midnight when it seems 4AM is
    still not available for running. Does anyone have a suggestion?

  • Imran Koradia

    #2
    Re: Time Problem


    "scorpion53 061" <admin@nospamhe rekjmsolutions. com> wrote in message
    news:ONvw2SQoEH A.1308@TK2MSFTN GP14.phx.gbl...[color=blue]
    > What I thought would be pretty easy has turned out not to be.
    >
    > I have three variables. Actiontime is formatted as 08/11/2004 11:03PM
    >
    > Actiontime
    > JobStreamStart (11:00:00PM)
    > JobStreamEnd (2:00:00AM)
    >
    > If (Format(CDate(A ctionTime), "t") >= JobStreamStart AND
    > (Format(CDate(A ctionTime), "t") < jobstreamend Then
    >
    > Do these actions
    >
    > End If
    >
    > Does not work. I am having a problem after midnight when it seems 4AM is
    > still not available for running. Does anyone have a suggestion?[/color]

    That's because 4 AM is not between 11PM and 2AM. Here's the way to go:

    Private Sub testsub()
    Dim ActionTime As DateTime = _
    DateTime.Parse( "08/11/2004 11:03PM")
    testtime(Action Time)
    ActionTime = DateTime.Parse( "08/12/04 04:00AM")
    testtime(Action Time)
    End Sub

    Private Sub testtime(ByVal ActionTime As DateTime)
    Dim StartTime As DateTime = DateTime.Parse( "08/11/04 11:00PM")
    Dim EndTime As DateTime = DateTime.Parse( "08/12/04 02:00AM")
    If (DateTime.Compa re(ActionTime, StartTime) >= 0 AndAlso _
    DateTime.Compar e(ActionTime, EndTime) < 0) OrElse _
    (DateTime.Compa re(ActionTime, StartTime) < 0 OrElse _
    DateTime.Compar e(ActionTime, EndTime) >= 0) Then
    MessageBox.Show ("Do These Actions..")
    End If
    End Sub

    or modifying your code:

    If ((Format(CDate( ActionTime), "t") >= JobStreamStart AndAlso _
    (Format(CDate(A ctionTime), "t") < jobstreamend)) OrElse _
    ((Format(CDate( ActionTime), "t") < JobStreamStart OrElse _
    (Format(CDate(A ctionTime), "t") >= jobstreamend)) Then
    MessageBox.Show ("Do These Actions..")
    End If

    hope that helps..
    Imran.


    Comment

    • scorpion53061

      #3
      Re: Time Problem

      My Bad I meant to say 1AM....

      If it says 1:00:00AM it still runs.



      "Imran Koradia" <nojunk@microso ft.com> wrote in message
      news:e07m8mQoEH A.3252@TK2MSFTN GP14.phx.gbl:[color=blue]
      > "scorpion53 061" <admin@nospamhe rekjmsolutions. com> wrote in message
      > news:ONvw2SQoEH A.1308@TK2MSFTN GP14.phx.gbl...[color=green]
      > > What I thought would be pretty easy has turned out not to be.
      > >
      > > I have three variables. Actiontime is formatted as 08/11/2004 11:03PM
      > >
      > > Actiontime
      > > JobStreamStart (11:00:00PM)
      > > JobStreamEnd (2:00:00AM)
      > >
      > > If (Format(CDate(A ctionTime), "t") >= JobStreamStart AND
      > > (Format(CDate(A ctionTime), "t") < jobstreamend Then
      > >
      > > Do these actions
      > >
      > > End If
      > >
      > > Does not work. I am having a problem after midnight when it seems 4AM
      > > is
      > > still not available for running. Does anyone have a suggestion?[/color]
      >
      > That's because 4 AM is not between 11PM and 2AM. Here's the way to go:
      >
      > Private Sub testsub()
      > Dim ActionTime As DateTime = _
      > DateTime.Parse( "08/11/2004 11:03PM")
      > testtime(Action Time)
      > ActionTime = DateTime.Parse( "08/12/04 04:00AM")
      > testtime(Action Time)
      > End Sub
      >
      > Private Sub testtime(ByVal ActionTime As DateTime)
      > Dim StartTime As DateTime = DateTime.Parse( "08/11/04 11:00PM")
      > Dim EndTime As DateTime = DateTime.Parse( "08/12/04 02:00AM")
      > If (DateTime.Compa re(ActionTime, StartTime) >= 0 AndAlso _
      > DateTime.Compar e(ActionTime, EndTime) < 0) OrElse _
      > (DateTime.Compa re(ActionTime, StartTime) < 0 OrElse _
      > DateTime.Compar e(ActionTime, EndTime) >= 0) Then
      > MessageBox.Show ("Do These Actions..")
      > End If
      > End Sub
      >
      > or modifying your code:
      >
      > If ((Format(CDate( ActionTime), "t") >= JobStreamStart AndAlso _
      > (Format(CDate(A ctionTime), "t") < jobstreamend)) OrElse _
      > ((Format(CDate( ActionTime), "t") < JobStreamStart OrElse _
      > (Format(CDate(A ctionTime), "t") >= jobstreamend)) Then
      > MessageBox.Show ("Do These Actions..")
      > End If
      >
      > hope that helps..
      > Imran.[/color]

      Comment

      Working...