check the date is in MM/DD/YYYY Format as the date datatype is string

Hi,

i have to do a validation for date which is in this format or not MM/DD/YYYY

And the data type for date i am using is string .

Can anyone help me on this.

Thanks

@avinashy

Convert.ToDateTime(YourString).ToString(MM/dd/yyyy)

This will convert as the format "MM/dd/yyyy)

Hope this helps

Thanks

@ksrinu070184 i am not trying to convert ,i am doing the validation here.

@avinashy
the try parse method can be used

@avinashy

Nice, for validation check as below

Below regex

^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$

Use Ismatch activity, so that you can get True / False

Mark as solution if this helps

Thanks

@ksrinu070184 , i can see that you are using wrong format in test text,again the date format is MM/DD/YYYY

Thanks

@avinashy

Try below

^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$

Hope this helps

Thanks