Date Reformatting

You have a string 'S' representing a date in the "Day Month Year" format, where:

  • Day is one of {"1st", "2nd", "3rd", ..., "29th", "30th", "31st"}.
  • Month is one of {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}.
  • Year is such as 2020, 2021, etc.

Your task is to reform this date into the "YYYY-MM-DD" format:

  • YYYY is a 4 digit year.
  • MM is a 2 digit month.
  • DD is a 2 digit day.

Input:

The first line contains an integer ‘T’, the number of test cases.
Each test case has a single string ‘S’ representing the date.

Output:

For each test case, output the date in "YYYY-MM-DD" format, each on a new line.

Example:

Input:
2
"1st Jan 2021"
"20th Oct 2020"

Output:
"2021-01-01"
"2020-10-20"

Constraints:

  • 1 <= T <= 104
  • Day: {"1st", "2nd", "3rd", ..., "31st"}
  • Month: {"Jan", "Feb", ..., "Dec"}
  • 1000 <= Year <= 2021
  • Time Limit: 1 second

Note:

  • Inputs are guaranteed to be valid.
  • If month or day is a single digit, prepend a 0. E.g., "Jan" becomes "01" and "5" becomes "05".
Be the first one to answer
Add answer anonymously...
Expedia Group Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter