CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2017
    Posts
    3

    VB.net code between two dates

    I have the following code:

    This one working ok,

    Code:
    Dim a As Date = "08/19/2017 02:00:00 PM"
    Dim b As Date = "08/19/2017 22:00:00 PM"
    
    If Now >= CDate(a) And Now <= CDate(b) Then
         MsgBox("ok")
    Else
         MsgBox("Not ok")
    End If
    But this one not working

    Code:
    Dim a As Date = "08/19/2017 08:00:00 PM"
    Dim b As Date = "08/20/2017 06:00:00 AM" 'next day
    
    If Now >= CDate(a) And Now <= CDate(b) Then
         MsgBox("ok")
    Else
         MsgBox("Not ok")
    End If
    any advice please
    Last edited by kmafsar; August 18th, 2017 at 05:59 PM. Reason: Added code tags

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: VB.net code between two dates

    hmm. given that you posted this at 4:13pm on 8/18 I don;t see how either of them could have given you the "ok" message.

    Of course you just said not working so I don't really know what you mean by that.

    It is worth noting that aside from the Dim statements you are basically using VB6 code there rather than VB.Net code

    Also of note; why are you using cDate()? both vars are already date type so there is no reason to convert a date to a date.
    Always use [code][/code] tags when posting code.

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

Featured