Compare Calendar Dates
Problem statement
Given two valid Gregorian calendar dates firstDate and secondDate in dd/mm/yyyy format, return the later date in the same format.
If the dates are equal, return firstDate.
Function
laterDate(firstDate: String, secondDate: String) → StringExamples
Example 1
firstDate = "15/04/2026"secondDate = "20/03/2027"return = "20/03/2027"The year 2027 is later than 2026.
Example 2
firstDate = "29/02/2024"secondDate = "01/03/2024"return = "01/03/2024"March 1 follows February 29 in the leap year 2024.
Example 3
firstDate = "07/09/2030"secondDate = "07/09/2030"return = "07/09/2030"The dates are equal, so the function returns firstDate.
Constraints
- Each input contains exactly
10characters indd/mm/yyyyformat. - Both inputs are valid Gregorian dates with years from
1900through9999. - Day and month values are zero-padded to two digits, and the year is zero-padded to four digits.