Ctrl K

Day Number in the Year

Easy
A date is written as the string stamp in the format YYYY-MM-DD (Gregorian calendar). Return which day of its year it is: 1 January is day 1, 2 January is day 2, and so on. As a reminder, a year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400. February has 29 days in a leap year.
Example 1
stamp='2016-03-01' → 61

January has 31 days, February 2016 has 29 (a leap year), plus 1 day of March: 61.

Example 2
stamp='1900-12-31' → 365

1900 is divisible by 100 but not by 400, so it is not a leap year and has 365 days.

Constraints
  • len(stamp) = 10, positions 4 and 7 hold hyphens, and every other character is a digit
  • The date exists and lies between 1 January 1900 and 31 December 2019
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Label EasySpreadsheet Column Index EasyCounting Off by Threes and Fives Easy
loading Python…
Input
stamp='2016-03-01'
Expected
61

Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.