web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

IsDate() Function??

(0) ShareShare
ReportReport
Posted on by 288

I have an Excel Spreadsheet where I need to validate if the cell in all the rows is formatted as a date field.

I can't seem to find a IsDate() function in either Excel Online Scripts or anything in Microsoft Flows that will validate if a field is formatted as a date in "1/1/2022" format.

 

Is there a way to validate a field is a date or not?

 

Thanks,
Mark

Categories:
I have the same question (0)
  • SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at

    @smithmrk ,

    Try formatDateTime()

    You could add an error handling branch to capture the case when its not a valid date.

     

    SudeepGhatakNZ_0-1666224942417.png

     

     

    SudeepGhatakNZ_1-1666225028511.png

     

  • Verified answer
    Yutao Huang Profile Picture
    Microsoft Employee on at

    As an alternate to @SudeepGhatakNZ's Power Automate solution, here is one in Office Scripts (based on this Stack Overflow answer )

     

     

     

    function main(workbook: ExcelScript.Workbook) {
     const dateString = workbook.getWorksheet("Sheet1").getRange("A1").getText();
     console.log(isValidDate(dateString) ? "VALID" : "INVALID");
    }
    
    // Validates that the input string is a valid date formatted as "mm/dd/yyyy"
    function isValidDate(dateString: string): boolean {
     // First check for the pattern
     if (!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
     return false;
    
     // Parse the date parts to integers
     var parts = dateString.split("/");
     var month = parseInt(parts[0], 10);
     var day = parseInt(parts[1], 10);
     var year = parseInt(parts[2], 10);
    
     // Check the ranges of month and year
     if (year < 1000 || year > 3000 || month == 0 || month > 12)
     return false;
    
     var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    
     // Adjust for leap years
     if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
     monthLength[1] = 29;
    
     // Check the range of the day
     return day > 0 && day <= monthLength[month - 1];
    };

     

     

     

    Please note you cannot simply rely on the built-in JavaScript Date object to do the date string parsing or validation (e.g., Date.parse(dateString)) since the behavior could vary based on the locale/culture settings of the computer. The above solution validates the date string against the explicit 'mm/dd/yyyy' format. It also checks different days of each month and leap years, etc. I feel it should be a pretty solid approach if you are looking for an Office Scripts solution.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 251 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 239

#3
Expiscornovus Profile Picture

Expiscornovus 220 Most Valuable Professional

Last 30 days Overall leaderboard