Date format check

Hi, I have date field whch has to be used for identifying whcih report needs to be created.I will get dates in YYYYMMDD and YYYY format
Can you please let me know is there any scala method which we can use to identify the date format and based jn the format generate particular report.