I am getting input as two types.
1.String date1 = "07/01/2017";
2.String date2 = ""2017-01-12 00:00:00.0";
How to compare two date formats. I want to perform one functionality if I get format as date1.If I get date2 format then Another functionality. How to compare two date formats using strings.
Ex:
if( date1.equals('dd/mm/yyyy')){
//perform functionality
}
If you want to know if the date is in format mm/dd/yyyy or mm-dd-yyyy or something in the same idea, you probably need to use regex expressions.
You can check this for a way to implement it What is the regular expression for Date format dd\mm\yyyy?
I guess, we can declare two date formats and parse the dates and compare the two Date instances. Here is sample code:
Use RegEx:
The solution with RegEx is good, but you can also do in this way:
The first parameter is your string representation of the date. The next parameter is var arg. So you can pass as many date formats as you wish. It will try to parse and if success then returns proper format.