Results 1 to 4 of 4

Thread: If not IsDate(txtMyDate.Text) not working

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2005
    Posts
    38

    If not IsDate(txtMyDate.Text) not working

    I have the following condition:

    But the date string is in this format "dd/MM/yyyy"

    If not IsDate(txtMyDate.Text) then

    I am getting an error message date is in wrong tstring format.

    Thank you very much foir the information.

  2. #2
    Frenzied Member
    Join Date
    Aug 2005
    Posts
    1,042

    Re: If not IsDate(txtMyDate.Text) not working

    reddymade1:

    Did you declare txtMyDate as date?
    Dim txtMyDate As Date

  3. #3
    Hyperactive Member BrendanDavis's Avatar
    Join Date
    Oct 2006
    Location
    Florida
    Posts
    492

    Re: If not IsDate(txtMyDate.Text) not working

    Quote Originally Posted by AIS4U
    reddymade1:

    Did you declare txtMyDate as date?
    Dim txtMyDate As Date
    It's a textbox, not a variable. If he was declaring it as a date variable, it would be logical to assume that it indeed WAS a date, and therefore he probably wouldn't need to be checking it.
    God put me on this earth to do many great things, and I'm so far behind that I'm going to live forever.

    I'm programming for Windows using a Apple Mac Mini, 1.5Ghz with 512MB DDR RAM. I feel like I'm committing a crime :P

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: If not IsDate(txtMyDate.Text) not working

    What you need is to use the TryParse method of the Date class.
    VB Code:
    1. Dim theDate As Date
    2. If Date.TryParse(txtMyDate.Text, theDate) Then
    3.      'This is a date
    4. Else
    5.      'The text is not in any date format
    6. End If

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