refactored code to get Date from String and String from Date