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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Is there a built-in function to check string is date or not ?

(0) ShareShare
ReportReport
Posted on by 395
Hi guys,
 
I'm reading data from CSV, and part of the data is a date. But as usual, there will be some value error usually relate to user given wrong date format, or the value not even a date. So when I'm put in variable Transdate, we get error. Is there built-in function to check whether the value we read is a date or not ?
 
Or how is the best way to handle this ?
 
Thanks,
I have the same question (0)
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    Sure, it's possible to do, but which function you should use depends on what exactly you need. Don't forget that there isn't a single format (e.g. 1\1\2012 or 15. července 2023 are also valid dates, although you'll likely want to reject them.
     
    For example, there is str2date() function or System.DateTime::ParseExact().
  • Teevo Profile Picture
    395 on at
    Hi Martin,
     
    But str2Date function means we already know the format, where is the position of the date, month, and year because we also need to specify sequence.
     
    I mean do we have function like IsDate() or something like that ? If I remembered correctly there is such function in PowerApps. It will return false if the parameter given is not a date.
     
    Thanks
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    If you don't know the format, you can't meaningfully decide whether it's a date or not. Are you sure that your CSV file can contain something like 15. července 2023 and you want to accept it as a date?
     
    If you don't want to specify a format, you must assume a particular format (or a few formats) under the hood.
  • Suggested answer
    Anthony Blake Profile Picture
    2,956 Super User 2025 Season 2 on at
    Have you considered using regex?
     
    It's horrible to read/write but there's load of examples on the web for date format validation, you could hide the ugliness away in a helper class.
     
     
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    In my opinion, trying to reimplement all the logic of System.Date::ParseExact() means spending a lot of time to get a worse result. Even such seemingly basic things like leap years are more complex than many developers realize. I wouldn't even think about it when we already have the solution available and tested for many years.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans