+ Reply to Thread
Results 1 to 10 of 10

Formula to validate an input date

  1. #1
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Formula to validate an input date

    Morning all,

    I've a document where you input the components of a date (day, month & year) into 3 different cells (A1, B1 & C1). How can I check that the date input is valid?

    NB - The values input are all numeric.

    Thanks in advance,

    Snook

  2. #2
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Formula to validate an input date

    what is valid? Just a real dates

    you can not know if the date is valid until all 3 boxes are complete, so data validation will not work (except preventing days above 31, months above 12 etc


    so an if statement or conditional formatting can flag iserror(date(c1,b1,a1))


    An attachment makes life so much easier

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Formula to validate an input date

    Hi,

    You could use another cell to check that each of the three cells are numeric with =ISNUMBER() but there are better ways.

    Why not just have a single cell to capture a date and make that a Data Validation cell that will only accept a date.

    Alternatively use a pop up calendar or UserForm that only allows the user to select a date. I'm attaching a file containing an example of the latter.
    A1 has the name 'startdate'

    Clicking this cell causes the form to pop up.
    Attached Files Attached Files
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,751

    Re: Formula to validate an input date

    you could use
    =DATEVALUE($A1&"/"&$B1&"/"&$C1)
    in a datavalidation

    BUT that will allow any year , as that will be a date
    you could add another validation for the year to be greater that a number like 2019
    Attached Files Attached Files
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  5. #5
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Formula to validate an input date

    Afternoon all,

    Apologies for the confusion, I've uploaded an example of what I'm working with. Essentially I require an output cell that validates the date formulated from the 3 input cells.

    I've added data val to the relevant cells to restrict the values input.

    My hands are tied on the structure as I've been asked to replicate a current online template.

    Thanks again,

    Snook

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,985

    Re: Formula to validate an input date

    Given the data validation you have on those fields, how could any input be invalid?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,751

    Re: Formula to validate an input date

    slight modification to my data validation suggestion
    =AND(NOT(ISERROR(DATEVALUE($B3&"/"&$C3&"/"&$D3))), $D3>=2020)

    your validation means that the 31 feb is possible
    or 31 september is possible

    But using the datevalue - has to be a valid date - so will account for leap years and 30/31 for most months and 28/29 for feb
    Last edited by etaf; 07-17-2020 at 09:48 AM.

  8. #8
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Formula to validate an input date

    Lol, good point.

    If a formula based check is available I'd be grateful of it, as it'll keep the powers that be happy if I can visually show that each element of the template is being checked.

    Plus, never underestimate the end user's ability to butcher a data input template! Someone will copy and paste 'July' over the month field, I can see it now.

    Snook

  9. #9
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Formula to validate an input date

    Nice one etaf, bang on the money!

    Thanks all,

    Snook

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,889

    Re: Formula to validate an input date

    To ensure that date string construct works across different system/region setting.
    You should use universally accepted pattern, yyyy-mm-dd. dd/mm/yyyy pattern will fail on US region setting.

    Replace Datevalue portion of etaf's formula to...
    DATEVALUE(D3&"-"&$C3&"-"&$B3)
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

+ 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. Using regex to validate input
    By Heathy65 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2018, 06:19 AM
  2. formula to validate start end date range tasks every month
    By alexcol in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-19-2014, 02:37 AM
  3. Validate two fields when one field you need a formula to validate
    By cmwilbur in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-29-2010, 11:32 AM
  4. Validate user input
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-31-2008, 04:56 PM
  5. Data - Validate - Input Message
    By LACA in forum Excel General
    Replies: 1
    Last Post: 10-24-2006, 03:53 PM
  6. Input Box Help - Validate Date Format
    By Tbal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-06-2005, 05:05 PM
  7. TEXTBOX - VALIDATE DATE INPUT
    By Steve_G in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2005, 12:05 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