+ Reply to Thread
Results 1 to 6 of 6

Validate a valid date

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    440

    Validate a valid date

    Hi.

    I know that IsDate() usually will return if a date is valid, but when a cell is format to Text, then I will use DateSerial to split to Date.
    However, it seems that the IsDate() is not working.

    I have set in A1 as date 20180230, and use the following code:
    Please Login or Register  to view this content.
    It will return true which is not correct.
    If I remove the IsDate(), and show msgbox dDate, it will show the next validate date which is 01 March 2018.

    Is there a way to identify a valid date from a text format?

    Thanks

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Validate a valid date

    Quote Originally Posted by calvinle View Post
    ... it seems that the IsDate() is not working.
    I have set in A1 as date 20180230, and use the following code:
    ...
    It will return true which is not correct.
    If I remove the IsDate(), and show msgbox dDate, it will show the next validate date which is 01 March 2018.
    Function works well, the date of 02-03-2018 is correct - fragment from 'Ms' description:

    "When any argument exceeds the accepted range for that argument, it increments to the next larger unit as appropriate. For example, if you specify 35 days, it is evaluated as one month and some number of days, depending on where in the year it is applied. If any single argument is outside the range -32,768 to 32,767, an error occurs. If the date specified by the three arguments falls outside the acceptable range of dates, an error occurs."
    Attached Images Attached Images

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    440

    Re: Validate a valid date

    I want the msgbox to tell me that the date 20180230 is false, because there is no 30 February.

  4. #4
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Validate a valid date

    IsDate doesnt check if the date is valid or not, it checks if the argument passed to it is a valid date/time format. See here

    For example some of the following would return true if passed to the IsDate function:
    • "12/24"
    • "10:55 AM"
    • "13.50"
    • "0.12"

    The above are of course not valid dates either. Id have to look and see if theres anything built in to actually validate the date itself...more than likely you will need to calculate it.

    EDIT: Off the top of my head, extract the month and assume day = 1, add 1 month and subtract 1 day will give you the last day of the extracted month. Store this and compare the extracted day to it (extracted day <= calc last day).
    Last edited by Zer0Cool; 11-20-2017 at 04:32 PM.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Validate a valid date

    Function ... full folk handicrafts ... , not tested too much:

    In text file because of strange communique from forum site ... ???
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Validate a valid date

    I have set in A1 as date 20180230...
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Validate data input against a list of multiple valid values
    By Grilleman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-21-2017, 12:55 PM
  2. Replies: 1
    Last Post: 06-15-2015, 03:25 PM
  3. Prompt user to enter date, then validate date, then continue with macro
    By rgiglio7489 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2014, 04:54 PM
  4. [SOLVED] How to i validate if all the values entered in userform textboxes are valid then execute.
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-01-2013, 12:33 PM
  5. [SOLVED] New to Forms-Validate a ComboBox and do something if not valid
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2013, 08:05 PM
  6. validate date value
    By talytech in forum Excel General
    Replies: 2
    Last Post: 06-01-2007, 04:56 PM
  7. Get Day from Date to Validate
    By David in forum Excel General
    Replies: 2
    Last Post: 08-20-2006, 09:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1