How to check if a string is a valid date time


I’ve scraped a string with this format (“dd/MM/yyyy”) and I want to check if corresponds to a valid date time, and obtain a boolean.

How to do this in UiPath? I tried TryParse method but it doesn’t work.


Will you tell us. what way you have tried?

Hi @nSangui,

Se if this is what you are looking for ?

I have done this for date and month , you can do it for the year.

dateformat.xaml (18.2 KB)



@prassin6 thanks for your code! It works.

I’ve also solved the problem with the next solution.

I’ve taken the string and I made substrings with the parts corresponding to the day, month and year.

After that I did a parse Integer of these substrings and for the days, if the string is between 1 and 31 it’s OK and for months between 1 and 12.

Thanks for your responses.

Cheers mate :slight_smile: Happy to help. Hit like when u find someone’s info helpfull.


I have the data of invoice stored in Excel in this format-

I want to check if the invoice_date is valid or not.
How can i do so??

@SHAISTA, Whats is your Criteria for checking whether a date is valid or not ?

1.> Is it the format of the date.
2.> Is it the values of the date.
3.> Does the date need to be within a particular date span(like 30 days , 40 days)

It is the values of the date i.e. days,month and year are correct or not.

Hope this helps :slight_smile:

1.> Get the Date value from Excel file - Store it in a variable date_from_excel

2.> Use Assign Activity with

To : Isdate_Correct

Value : DateTime.Parse(date_from_excel)

Note : Isdate_Correct is of type DateTime

Surround it with Try / Catch block (I mean the Assign activity)

in the catch block use a msg box with "NOT a Valid Date "

Come out of try catch block and put a msg box with below

"Valid Date " + Isdate_Correct.ToString(“dd-MM-yyyy”)

So if the date taken from excel is of format dd-MM-yyyy() then this msg box will be displayed.

or else it will throw an error that its an invalid date.

Main - Copy.xaml (9.0 KB)

1 Like