time compare? should be simple

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

    time compare? should be simple

    I have a datetimepicker formated for just time, the user selects the time.
    I want to compare if that time is between midnight and 8 am
    dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#

    this evaluates to true when the time is not greater than

    dtmTime #9:32:34 PM#

    Why is that? and How can I get this to work?
    Brian


  • Cor Ligthert[MVP]

    #2
    Re: time compare? should be simple

    Brian,

    Maybe it is more simple (at least for me, not somebody from an English
    culture), to use New Datetime.

    dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
    Now,Day,8,0,0)

    If a < Now then it is behind 8 o'clcok

    Cor

    "Brian" <bsgallatin@com munity.nospamsc hreef in bericht
    news:OiH4Ip7PJH A.4884@TK2MSFTN GP04.phx.gbl...
    >I have a datetimepicker formated for just time, the user selects the time.
    I want to compare if that time is between midnight and 8 am
    dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
    >
    this evaluates to true when the time is not greater than
    >
    dtmTime #9:32:34 PM#
    >
    Why is that? and How can I get this to work?
    Brian
    >
    >

    Comment

    • Brian

      #3
      Re: time compare? should be simple

      not really sure what you mean there.. I have dtmTime defined as datetime
      and when I do immed on it.. is
      #11/5/2008 9:44:07 PM# but in my code posted previously... this was
      evaluating to than midnight

      "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
      news:O3PT7VAQJH A.4084@TK2MSFTN GP04.phx.gbl...
      Brian,
      >
      Maybe it is more simple (at least for me, not somebody from an English
      culture), to use New Datetime.
      >
      dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
      Now,Day,8,0,0)
      >
      If a < Now then it is behind 8 o'clcok
      >
      Cor
      >
      "Brian" <bsgallatin@com munity.nospamsc hreef in bericht
      news:OiH4Ip7PJH A.4884@TK2MSFTN GP04.phx.gbl...
      >>I have a datetimepicker formated for just time, the user selects the time.
      >I want to compare if that time is between midnight and 8 am
      >dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
      >>
      >this evaluates to true when the time is not greater than
      >>
      >dtmTime #9:32:34 PM#
      >>
      >Why is that? and How can I get this to work?
      > Brian
      >>
      >>
      >
      >

      Comment

      • Armin Zingler

        #4
        Re: time compare? should be simple

        "Brian" <bsgallatin@com munity.nospamsc hrieb
        not really sure what you mean there.. I have dtmTime defined as datetime
        and when I do immed on it.. is
        #11/5/2008 9:44:07 PM# but in my code posted previously... this was
        evaluating to than midnight

        Isn't everything than midnight?


        Try comparing the TimeOfDay only (YourDateTimePi cker.Value.Time OfDay)


        Armin

        Comment

        • Brian

          #5
          Re: time compare? should be simple

          this is what i get using the timeofday....

          Overload resolution failed because no accessible '>' can be called with
          these arguments:

          'Public Shared Operator >(t1 As Date, t2 As Date) As Boolean': Value of type
          'System.TimeSpa n' cannot be converted to 'Date'.

          'Public Shared Operator >(t1 As System.TimeSpan , t2 As System.TimeSpan ) As
          Boolean': Value of type 'Date' cannot be converted to 'System.TimeSpa n'.



          If dtmTime #11:59:59 PM# And dtmTime < #08:00# Then

          I would like for that to be true if the dtmTime is between those times..
          otherwise false... dtmTime is defined as DateTime





          "Armin Zingler" <az.nospam@free net.dewrote in message
          news:eyVXX2BQJH A.1148@TK2MSFTN GP05.phx.gbl...
          "Brian" <bsgallatin@com munity.nospamsc hrieb
          >not really sure what you mean there.. I have dtmTime defined as datetime
          >and when I do immed on it.. is
          >#11/5/2008 9:44:07 PM# but in my code posted previously... this was
          >evaluating to than midnight
          >
          >
          Isn't everything than midnight?
          >
          >
          Try comparing the TimeOfDay only (YourDateTimePi cker.Value.Time OfDay)
          >
          >
          Armin

          Comment

          • =?Utf-8?B?T21lZ2FTcXVhcmVk?=

            #6
            RE: time compare? should be simple

            Hello, Brian,

            I'm a bit confused about what you are trying to do.

            Re: "...formate d for just time,"

            As far as I know, the value returned by the DateTimePicker will include the
            date even if the display is formatted to show only time. Perhaps your
            problem is that you still need to truncate that date.

            Re: "dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#"

            You say this evaluates to True. But I think that there are not many (by
            that I mean any) times for which the above statement would evaluate to True.
            Don't you just want the second half of that statement. I.e.: "dtmTime <
            #08:00:00 AM#"

            Cheers,
            Randy

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: time compare? should be simple

              I thought you did want every time behind 8 0'clock today.

              But It is simple from this code that it goes only for today

              I had first
              dim b = new DateTime(New DateTime(now.Ye ar,now.Month, Now,Day, 24,0,0)

              dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
              Now,Day,8,0,0)

              If a < Now and also Now < B then it is between 8 and 24 o'clock

              Cor

              "Brian" <bsgallatin@com munity.nospamwr ote in message
              news:uaHtT6AQJH A.4992@TK2MSFTN GP05.phx.gbl...
              not really sure what you mean there.. I have dtmTime defined as datetime
              and when I do immed on it.. is
              #11/5/2008 9:44:07 PM# but in my code posted previously... this was
              evaluating to than midnight
              >
              "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
              news:O3PT7VAQJH A.4084@TK2MSFTN GP04.phx.gbl...
              >Brian,
              >>
              >Maybe it is more simple (at least for me, not somebody from an English
              >culture), to use New Datetime.
              >>
              >dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
              >Now,Day,8,0, 0)
              >>
              >If a < Now then it is behind 8 o'clcok
              >>
              >Cor
              >>
              >"Brian" <bsgallatin@com munity.nospamsc hreef in bericht
              >news:OiH4Ip7PJ HA.4884@TK2MSFT NGP04.phx.gbl.. .
              >>>I have a datetimepicker formated for just time, the user selects the
              >>>time.
              >>I want to compare if that time is between midnight and 8 am
              >>dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
              >>>
              >>this evaluates to true when the time is not greater than
              >>>
              >>dtmTime #9:32:34 PM#
              >>>
              >>Why is that? and How can I get this to work?
              >> Brian
              >>>
              >>>
              >>
              >>
              >
              >

              Comment

              • Brian

                #8
                Re: time compare? should be simple

                well no, I want any time that is between midnight and 8am to be true...

                "OmegaSquar ed" <OmegaSquared@d iscussions.micr osoft.comwrote in message
                news:F4AB2851-A4E9-4597-BECF-16FB2CBD2465@mi crosoft.com...
                Hello, Brian,
                >
                I'm a bit confused about what you are trying to do.
                >
                Re: "...formate d for just time,"
                >
                As far as I know, the value returned by the DateTimePicker will include
                the
                date even if the display is formatted to show only time. Perhaps your
                problem is that you still need to truncate that date.
                >
                Re: "dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#"
                >
                You say this evaluates to True. But I think that there are not many (by
                that I mean any) times for which the above statement would evaluate to
                True.
                Don't you just want the second half of that statement. I.e.: "dtmTime <
                #08:00:00 AM#"
                >
                Cheers,
                Randy
                >

                Comment

                • Armin Zingler

                  #9
                  Re: time compare? should be simple

                  "Brian" <bsgallatin@com munity.nospamsc hrieb
                  this is what i get using the timeofday....
                  >
                  Overload resolution failed because no accessible '>' can be called
                  with these arguments:
                  >
                  'Public Shared Operator >(t1 As Date, t2 As Date) As Boolean': Value
                  of type 'System.TimeSpa n' cannot be converted to 'Date'.
                  >
                  'Public Shared Operator >(t1 As System.TimeSpan , t2 As
                  System.TimeSpan ) As Boolean': Value of type 'Date' cannot be
                  converted to 'System.TimeSpa n'.
                  >
                  >
                  >
                  If dtmTime #11:59:59 PM# And dtmTime < #08:00# Then
                  >
                  I would like for that to be true if the dtmTime is between those
                  times.. otherwise false... dtmTime is defined as DateTime
                  If dtmTime is a DateTime object, the last line should be compilable.
                  #11:59:59 PM# is actually 01/01/0001 11:59:59 PM and
                  #08:00# is actually 01/01/0001 08:00 AM

                  However, you want to compare times, not points in time. A TimeSpan object is
                  usually used to represent the time of a day, like the TimeOfDay property of
                  a DateTime object shows. It's the timespan from midnight until the time
                  given.

                  So, dtmTime should be a TimeSpan variable. Then the statement is:

                  If dtmTime New TimeSpan AndAlso dtmTime < New TimeSpan(8, 0, 0) Then

                  Instead of
                  dtmTime New TimeSpan
                  you can also use
                  dtmTime.Ticks 0
                  or
                  dtmTime New Timespan(0)
                  or
                  ...


                  I don't know if midnight is to be included or excluded. It it's included,
                  the first expression is not required at all because ever time is equal to or
                  after midnight.


                  Armin

                  Comment

                  • Brian

                    #10
                    Re: time compare? should be simple

                    ok, i guess i am just not getting.. let me rephase what I am doing and you
                    tell me what is best to here
                    i have a function that accepts to varibles.. dtmdate as date, dtmTime as
                    date
                    Public Function GetShift(ByVal dtmDate As Date, ByVal dtmTime As DateTime)
                    As String



                    If dtmTime #11:59:59 PM# And dtmTime < ShiftEndTime Then

                    strShift = "N"

                    dtmDate.AddDays (-1)



                    End If

                    return getshift(dtmDat e, "N")

                    Now, if this function is ran between midnight and 8 am then I subtract 1 day
                    to get the team that started its night shift the previous day.
                    Not sure i am having a hard time understanding.. maybe i need a
                    vacation...lol


                    "Cor Ligthert[MVP]" <Notmyfirstname @planet.nlwrote in message
                    news:%23lnrZpDQ JHA.728@TK2MSFT NGP05.phx.gbl.. .
                    >I thought you did want every time behind 8 0'clock today.
                    >
                    But It is simple from this code that it goes only for today
                    >
                    I had first
                    dim b = new DateTime(New DateTime(now.Ye ar,now.Month, Now,Day, 24,0,0)
                    >
                    dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
                    Now,Day,8,0,0)
                    >
                    If a < Now and also Now < B then it is between 8 and 24 o'clock
                    >
                    Cor
                    >
                    "Brian" <bsgallatin@com munity.nospamwr ote in message
                    news:uaHtT6AQJH A.4992@TK2MSFTN GP05.phx.gbl...
                    >not really sure what you mean there.. I have dtmTime defined as datetime
                    >and when I do immed on it.. is
                    >#11/5/2008 9:44:07 PM# but in my code posted previously... this was
                    >evaluating to than midnight
                    >>
                    >"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                    >news:O3PT7VAQJ HA.4084@TK2MSFT NGP04.phx.gbl.. .
                    >>Brian,
                    >>>
                    >>Maybe it is more simple (at least for me, not somebody from an English
                    >>culture), to use New Datetime.
                    >>>
                    >>dim a (as DateTime for older versions) = new
                    >>DateTime(now. Year,now.Month, Now,Day,8,0,0)
                    >>>
                    >>If a < Now then it is behind 8 o'clcok
                    >>>
                    >>Cor
                    >>>
                    >>"Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                    >>news:OiH4Ip7P JHA.4884@TK2MSF TNGP04.phx.gbl. ..
                    >>>>I have a datetimepicker formated for just time, the user selects the
                    >>>>time.
                    >>>I want to compare if that time is between midnight and 8 am
                    >>>dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
                    >>>>
                    >>>this evaluates to true when the time is not greater than
                    >>>>
                    >>>dtmTime #9:32:34 PM#
                    >>>>
                    >>>Why is that? and How can I get this to work?
                    >>> Brian
                    >>>>
                    >>>>
                    >>>
                    >>>
                    >>
                    >>
                    >

                    Comment

                    • =?Utf-8?B?T21lZ2FTcXVhcmVk?=

                      #11
                      Re: time compare? should be simple

                      Hello, Brian,

                      Re: "well no, I want any time that is between midnight and 8am to be true..."

                      Ummm.... and can you tell me for what time between midnight and 8am the
                      result of:
                      dtmTime < #08:00:00 AM#

                      would not be True? The only one that comes to my mind is midnight itself.
                      So if you want your interval to exclude midnight, then try:

                      dtmTime #00:00:00 AM# AND dtmTime < #08:00:00 AM#

                      Cheers,
                      Randy

                      Comment

                      • Stephany Young

                        #12
                        Re: time compare? should be simple

                        Yes, you are not getting it!

                        Firstly, when you post, please use appropriate punction and grammar. This
                        will make your posting a lot easier for to understand.

                        A variable of type DateTime represents a point in time. A point in time
                        always comprises both a date and a time of day.

                        If you populate such a variable with only a time part (say 8:00 AM) then the
                        value of the variable will be the system date combined with the time that
                        you specified, e.g.:

                        Dim MyVar = DateTime.Parse( "08:00")

                        Console.Writeli ne(MyVar)

                        will result in #11/7/2008 8:00 AM#, or something like that, depending on
                        your system locale and your regional settings.

                        Obversely, if you populate such a variable with only a date part then the
                        value of the variable will be the date you specified combined with midnight,
                        e.g.:

                        Dim MyVar = DateTime.Today

                        Console.Writeli ne(MyVar)

                        will result in #11/7/2008 12:00 AM#, or something like that, depending on
                        your system locale and your regional settings.

                        An important point that you MUST ALWAYS remember is that midnight (12:00 AM)
                        is at the BEGINNING of the day and not at the end of the day.

                        If, as it appears, you want to know if any given point in time is prior to
                        8:00 AM today then you have a number of options:

                        If MyPointInTime < DateTime.Today. AddHours(8) Then
                        ' MyPointInTime is prior to 8:00 AM today
                        End If

                        If MyPointInTime.D ate = DateTime.Today AndAlso MyPointInTime.H our < 8
                        Then
                        ' MyPointInTime is prior to 8:00 AM today
                        End If

                        If DateTime.Today. AddHours(8).Sub tract(MyPointIn Time).TotalHour s 8
                        ' MyPointInTime is prior to 8:00 AM today
                        End If

                        The options shown here are, by no means, definitive.

                        I strongly recommend that you review and experiment with the properties and
                        methods of the DateTime and TimeSpan types so that you become conversant
                        with what they represent and how they operate.


                        "Brian" <bsgallatin@com munity.nospamwr ote in message
                        news:uucyjrIQJH A.4992@TK2MSFTN GP05.phx.gbl...
                        ok, i guess i am just not getting.. let me rephase what I am doing and you
                        tell me what is best to here
                        i have a function that accepts to varibles.. dtmdate as date, dtmTime as
                        date
                        Public Function GetShift(ByVal dtmDate As Date, ByVal dtmTime As DateTime)
                        As String
                        >
                        >
                        >
                        If dtmTime #11:59:59 PM# And dtmTime < ShiftEndTime Then
                        >
                        strShift = "N"
                        >
                        dtmDate.AddDays (-1)
                        >
                        >
                        >
                        End If
                        >
                        return getshift(dtmDat e, "N")
                        >
                        Now, if this function is ran between midnight and 8 am then I subtract 1
                        day to get the team that started its night shift the previous day.
                        Not sure i am having a hard time understanding.. maybe i need a
                        vacation...lol
                        >
                        >
                        "Cor Ligthert[MVP]" <Notmyfirstname @planet.nlwrote in message
                        news:%23lnrZpDQ JHA.728@TK2MSFT NGP05.phx.gbl.. .
                        >>I thought you did want every time behind 8 0'clock today.
                        >>
                        >But It is simple from this code that it goes only for today
                        >>
                        >I had first
                        >dim b = new DateTime(New DateTime(now.Ye ar,now.Month, Now,Day, 24,0,0)
                        >>
                        >dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
                        >Now,Day,8,0, 0)
                        >>
                        >If a < Now and also Now < B then it is between 8 and 24 o'clock
                        >>
                        >Cor
                        >>
                        >"Brian" <bsgallatin@com munity.nospamwr ote in message
                        >news:uaHtT6AQJ HA.4992@TK2MSFT NGP05.phx.gbl.. .
                        >>not really sure what you mean there.. I have dtmTime defined as datetime
                        >>and when I do immed on it.. is
                        >>#11/5/2008 9:44:07 PM# but in my code posted previously... this was
                        >>evaluating to than midnight
                        >>>
                        >>"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                        >>news:O3PT7VAQ JHA.4084@TK2MSF TNGP04.phx.gbl. ..
                        >>>Brian,
                        >>>>
                        >>>Maybe it is more simple (at least for me, not somebody from an English
                        >>>culture), to use New Datetime.
                        >>>>
                        >>>dim a (as DateTime for older versions) = new
                        >>>DateTime(now .Year,now.Month , Now,Day,8,0,0)
                        >>>>
                        >>>If a < Now then it is behind 8 o'clcok
                        >>>>
                        >>>Cor
                        >>>>
                        >>>"Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                        >>>news:OiH4Ip7 PJHA.4884@TK2MS FTNGP04.phx.gbl ...
                        >>>>>I have a datetimepicker formated for just time, the user selects the
                        >>>>>time.
                        >>>>I want to compare if that time is between midnight and 8 am
                        >>>>dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
                        >>>>>
                        >>>>this evaluates to true when the time is not greater than
                        >>>>>
                        >>>>dtmTime #9:32:34 PM#
                        >>>>>
                        >>>>Why is that? and How can I get this to work?
                        >>>> Brian
                        >>>>>
                        >>>>>
                        >>>>
                        >>>>
                        >>>
                        >>>
                        >>
                        >
                        >

                        Comment

                        • James Hahn

                          #13
                          Re: time compare? should be simple

                          For the line
                          If dtmTime #11:59:59 PM# And dtmTime < ShiftEndTime Then
                          to work it would have to somehow be interpreted as

                          If dtmTime is greater than '11:59:59 PM yesterday' and is also less than
                          'ShiftEndTime today' then ...

                          and I can't see anything in your code that enables that interpretation.

                          If that really was a time object you were comparing (which I believe it
                          isn't) then surely the comparison should be to 00:00:00.

                          "Brian" <bsgallatin@com munity.nospamwr ote in message
                          news:uucyjrIQJH A.4992@TK2MSFTN GP05.phx.gbl...
                          ok, i guess i am just not getting.. let me rephase what I am doing and you
                          tell me what is best to here
                          i have a function that accepts to varibles.. dtmdate as date, dtmTime as
                          date
                          Public Function GetShift(ByVal dtmDate As Date, ByVal dtmTime As DateTime)
                          As String
                          >
                          >
                          >
                          If dtmTime #11:59:59 PM# And dtmTime < ShiftEndTime Then
                          >
                          strShift = "N"
                          >
                          dtmDate.AddDays (-1)
                          >
                          >
                          >
                          End If
                          >
                          return getshift(dtmDat e, "N")
                          >
                          Now, if this function is ran between midnight and 8 am then I subtract 1
                          day to get the team that started its night shift the previous day.
                          Not sure i am having a hard time understanding.. maybe i need a
                          vacation...lol
                          >
                          >
                          "Cor Ligthert[MVP]" <Notmyfirstname @planet.nlwrote in message
                          news:%23lnrZpDQ JHA.728@TK2MSFT NGP05.phx.gbl.. .
                          >>I thought you did want every time behind 8 0'clock today.
                          >>
                          >But It is simple from this code that it goes only for today
                          >>
                          >I had first
                          >dim b = new DateTime(New DateTime(now.Ye ar,now.Month, Now,Day, 24,0,0)
                          >>
                          >dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
                          >Now,Day,8,0, 0)
                          >>
                          >If a < Now and also Now < B then it is between 8 and 24 o'clock
                          >>
                          >Cor
                          >>
                          >"Brian" <bsgallatin@com munity.nospamwr ote in message
                          >news:uaHtT6AQJ HA.4992@TK2MSFT NGP05.phx.gbl.. .
                          >>not really sure what you mean there.. I have dtmTime defined as datetime
                          >>and when I do immed on it.. is
                          >>#11/5/2008 9:44:07 PM# but in my code posted previously... this was
                          >>evaluating to than midnight
                          >>>
                          >>"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                          >>news:O3PT7VAQ JHA.4084@TK2MSF TNGP04.phx.gbl. ..
                          >>>Brian,
                          >>>>
                          >>>Maybe it is more simple (at least for me, not somebody from an English
                          >>>culture), to use New Datetime.
                          >>>>
                          >>>dim a (as DateTime for older versions) = new
                          >>>DateTime(now .Year,now.Month , Now,Day,8,0,0)
                          >>>>
                          >>>If a < Now then it is behind 8 o'clcok
                          >>>>
                          >>>Cor
                          >>>>
                          >>>"Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                          >>>news:OiH4Ip7 PJHA.4884@TK2MS FTNGP04.phx.gbl ...
                          >>>>>I have a datetimepicker formated for just time, the user selects the
                          >>>>>time.
                          >>>>I want to compare if that time is between midnight and 8 am
                          >>>>dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
                          >>>>>
                          >>>>this evaluates to true when the time is not greater than
                          >>>>>
                          >>>>dtmTime #9:32:34 PM#
                          >>>>>
                          >>>>Why is that? and How can I get this to work?
                          >>>> Brian
                          >>>>>
                          >>>>>
                          >>>>
                          >>>>
                          >>>
                          >>>
                          >>
                          >
                          >

                          Comment

                          • Cor Ligthert[MVP]

                            #14
                            Re: time compare? should be simple

                            Brian.

                            As you look at Stephany's correct reply, then there is one different with my
                            code.

                            I have written that the time today between 8 and 24 o'clock, is not the
                            time from 00 to 08 o'clock

                            So there is something different. Is exactly 8 o'clock including what your
                            want or excluded from what you want.

                            Cor

                            "Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                            news:uucyjrIQJH A.4992@TK2MSFTN GP05.phx.gbl...
                            ok, i guess i am just not getting.. let me rephase what I am doing and you
                            tell me what is best to here
                            i have a function that accepts to varibles.. dtmdate as date, dtmTime as
                            date
                            Public Function GetShift(ByVal dtmDate As Date, ByVal dtmTime As DateTime)
                            As String
                            >
                            >
                            >
                            If dtmTime #11:59:59 PM# And dtmTime < ShiftEndTime Then
                            >
                            strShift = "N"
                            >
                            dtmDate.AddDays (-1)
                            >
                            >
                            >
                            End If
                            >
                            return getshift(dtmDat e, "N")
                            >
                            Now, if this function is ran between midnight and 8 am then I subtract 1
                            day to get the team that started its night shift the previous day.
                            Not sure i am having a hard time understanding.. maybe i need a
                            vacation...lol
                            >
                            >
                            "Cor Ligthert[MVP]" <Notmyfirstname @planet.nlwrote in message
                            news:%23lnrZpDQ JHA.728@TK2MSFT NGP05.phx.gbl.. .
                            >>I thought you did want every time behind 8 0'clock today.
                            >>
                            >But It is simple from this code that it goes only for today
                            >>
                            >I had first
                            >dim b = new DateTime(New DateTime(now.Ye ar,now.Month, Now,Day, 24,0,0)
                            >>
                            >dim a (as DateTime for older versions) = new DateTime(now.Ye ar,now.Month,
                            >Now,Day,8,0, 0)
                            >>
                            >If a < Now and also Now < B then it is between 8 and 24 o'clock
                            >>
                            >Cor
                            >>
                            >"Brian" <bsgallatin@com munity.nospamwr ote in message
                            >news:uaHtT6AQJ HA.4992@TK2MSFT NGP05.phx.gbl.. .
                            >>not really sure what you mean there.. I have dtmTime defined as datetime
                            >>and when I do immed on it.. is
                            >>#11/5/2008 9:44:07 PM# but in my code posted previously... this was
                            >>evaluating to than midnight
                            >>>
                            >>"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                            >>news:O3PT7VAQ JHA.4084@TK2MSF TNGP04.phx.gbl. ..
                            >>>Brian,
                            >>>>
                            >>>Maybe it is more simple (at least for me, not somebody from an English
                            >>>culture), to use New Datetime.
                            >>>>
                            >>>dim a (as DateTime for older versions) = new
                            >>>DateTime(now .Year,now.Month , Now,Day,8,0,0)
                            >>>>
                            >>>If a < Now then it is behind 8 o'clcok
                            >>>>
                            >>>Cor
                            >>>>
                            >>>"Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                            >>>news:OiH4Ip7 PJHA.4884@TK2MS FTNGP04.phx.gbl ...
                            >>>>>I have a datetimepicker formated for just time, the user selects the
                            >>>>>time.
                            >>>>I want to compare if that time is between midnight and 8 am
                            >>>>dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
                            >>>>>
                            >>>>this evaluates to true when the time is not greater than
                            >>>>>
                            >>>>dtmTime #9:32:34 PM#
                            >>>>>
                            >>>>Why is that? and How can I get this to work?
                            >>>> Brian
                            >>>>>
                            >>>>>
                            >>>>
                            >>>>
                            >>>
                            >>>
                            >>
                            >
                            >

                            Comment

                            • Brian

                              #15
                              Re: time compare? should be simple

                              8 would be the start of the next shift, I will try stephany's sample and i
                              need to play around with the timespan.. and ticks... and read more on the
                              msdn.
                              Thanks

                              "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                              news:uqRCtwMQJH A.4004@TK2MSFTN GP03.phx.gbl...
                              Brian.
                              >
                              As you look at Stephany's correct reply, then there is one different with
                              my code.
                              >
                              I have written that the time today between 8 and 24 o'clock, is not the
                              time from 00 to 08 o'clock
                              >
                              So there is something different. Is exactly 8 o'clock including what your
                              want or excluded from what you want.
                              >
                              Cor
                              >
                              "Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                              news:uucyjrIQJH A.4992@TK2MSFTN GP05.phx.gbl...
                              >ok, i guess i am just not getting.. let me rephase what I am doing and
                              >you tell me what is best to here
                              >i have a function that accepts to varibles.. dtmdate as date, dtmTime as
                              >date
                              >Public Function GetShift(ByVal dtmDate As Date, ByVal dtmTime As
                              >DateTime) As String
                              >>
                              >>
                              >>
                              >If dtmTime #11:59:59 PM# And dtmTime < ShiftEndTime Then
                              >>
                              >strShift = "N"
                              >>
                              >dtmDate.AddDay s(-1)
                              >>
                              >>
                              >>
                              >End If
                              >>
                              >return getshift(dtmDat e, "N")
                              >>
                              >Now, if this function is ran between midnight and 8 am then I subtract 1
                              >day to get the team that started its night shift the previous day.
                              >Not sure i am having a hard time understanding.. maybe i need a
                              >vacation...l ol
                              >>
                              >>
                              >"Cor Ligthert[MVP]" <Notmyfirstname @planet.nlwrote in message
                              >news:%23lnrZpD QJHA.728@TK2MSF TNGP05.phx.gbl. ..
                              >>>I thought you did want every time behind 8 0'clock today.
                              >>>
                              >>But It is simple from this code that it goes only for today
                              >>>
                              >>I had first
                              >>dim b = new DateTime(New DateTime(now.Ye ar,now.Month, Now,Day, 24,0,0)
                              >>>
                              >>dim a (as DateTime for older versions) = new
                              >>DateTime(now. Year,now.Month,
                              >>Now,Day,8,0,0 )
                              >>>
                              >>If a < Now and also Now < B then it is between 8 and 24 o'clock
                              >>>
                              >>Cor
                              >>>
                              >>"Brian" <bsgallatin@com munity.nospamwr ote in message
                              >>news:uaHtT6AQ JHA.4992@TK2MSF TNGP05.phx.gbl. ..
                              >>>not really sure what you mean there.. I have dtmTime defined as
                              >>>datetime
                              >>>and when I do immed on it.. is
                              >>>#11/5/2008 9:44:07 PM# but in my code posted previously... this was
                              >>>evaluating to than midnight
                              >>>>
                              >>>"Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                              >>>news:O3PT7VA QJHA.4084@TK2MS FTNGP04.phx.gbl ...
                              >>>>Brian,
                              >>>>>
                              >>>>Maybe it is more simple (at least for me, not somebody from an English
                              >>>>culture), to use New Datetime.
                              >>>>>
                              >>>>dim a (as DateTime for older versions) = new
                              >>>>DateTime(no w.Year,now.Mont h, Now,Day,8,0,0)
                              >>>>>
                              >>>>If a < Now then it is behind 8 o'clcok
                              >>>>>
                              >>>>Cor
                              >>>>>
                              >>>>"Brian" <bsgallatin@com munity.nospamsc hreef in bericht
                              >>>>news:OiH4Ip 7PJHA.4884@TK2M SFTNGP04.phx.gb l...
                              >>>>>>I have a datetimepicker formated for just time, the user selects the
                              >>>>>>time.
                              >>>>>I want to compare if that time is between midnight and 8 am
                              >>>>>dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM#
                              >>>>>>
                              >>>>>this evaluates to true when the time is not greater than
                              >>>>>>
                              >>>>>dtmTime #9:32:34 PM#
                              >>>>>>
                              >>>>>Why is that? and How can I get this to work?
                              >>>>> Brian
                              >>>>>>
                              >>>>>>
                              >>>>>
                              >>>>>
                              >>>>
                              >>>>
                              >>>
                              >>
                              >>
                              >
                              >

                              Comment

                              Working...