Question: Scripting (Python,R,etc): Write a function, min_date(string), that has the input of XXXX-XX-XX where: The string represents a date in YYYY-MM-DD format. So, 1234-56-7 is invalid

Scripting (Python,R,etc):

Write a function, min_date(string), that has the input of XXXX-XX-XX where:

  1. The string represents a date in YYYY-MM-DD format. So, 1234-56-7 is invalid
  2. There is no need to check that this value is a valid date. So, 1234-56-78 is valid
  3. Only valid date inputs will be used to test this function (so you do not need to handle non-date inputs if you dont want to). So, your function will not have to run a value with 1234-56-78 as an input (unless you want it to).

This function gives the output of YYYY-MM-DD, where the output is the closest real date given the following rules:

  1. The digits are 0 to 7. So, the date 3456-09-12 is invalid
  2. No number is repeated. So, the date 1234-09-15 is invalid
  3. The output date is a valid date. So, the date 6035-12-40 is invalid

You are given the following functions (but are free to not use them):

Examples of output:

min_date(7654-01-22)

> 7654-01-23

min_date(2020-12-24)

> 2345-06-17

min_date(0001-01-01)

  • 1345-06-27

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!