Skip to content

Practice Reformat Date

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1507
LeetCode Problem

Reformat Date

Problem Statement

Convert a valid date from Day Month Year to YYYY-MM-DD. Day is an ordinal such as 1st, 2nd, 3rd or 31st. Month uses Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec. Year is from 1900 through 2100. Output the four-digit year, then two-digit month and day with leading zeros when needed, separated by hyphens.

Source: Reformat Date on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
date = "20th Oct 2052"
Output
"2052-10-20"

# Example 2

Input
date = "6th Jun 1933"
Output
"1933-06-06"

# Example 3

Input
date = "26th May 1960"
Output
"1960-05-26"

Constraints

The given dates are guaranteed to be valid, so no error handling is necessary.

Related LeetCode Problems

Practice more problems similar to Reformat Date.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.