Results 1 to 6 of 6

Thread: When is a date not a date?

  1. #1

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Question When is a date not a date?

    Can anyone give me a convincing explanation why this returns True in both cases?

    Debug.Print IsDate("59/12/08")
    Debug.Print IsDate("39/11/06")
    Another light-hearted post from Guru

  2. #2

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Re: When is a date not a date?

    I know why; it guesses at the year!
    Another light-hearted post from Guru

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: When is a date not a date?

    According to MS:

    Function IsDate(Expression) As Boolean
    Member of VBA.Information
    Returns True if an expression can be converted to a date

  4. #4

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Re: When is a date not a date?

    It's daft because it guesses at the format.

    I want to pass it a string I know to be in the format DD/MM/YY
    so, 59/12/08 is obviously not a valid date.

    Nevermind, I'll knock something up myself...


    All dates are going to be in this centaury so Ill just prepend "20" to the year field
    Another light-hearted post from Guru

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: When is a date not a date?

    Quote Originally Posted by Guru
    I want to pass it a string I know to be in the format DD/MM/YY
    so, 59/12/08 is obviously not a valid date.
    But, it is a valid date format and, as gavio has intimated, that is all IsDate will confirm (or deny).

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: When is a date not a date?

    Type this in some sub in VB:

    Code:
    Dim d As Date
      d = #59/12/08#
    and move the cursor off the "d =" line. That's why 59/12/08 is a valid date.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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