HomeChallengesRepsProblemsLeaderboardTake a challenge

Dates are just numbers

A date is stored as 20160229. Take it apart into a year, a month and a day, and put it back together, using arithmetic only.

Beginner5 min on the clock5 graded checks · 100 pointsFrom Procedures to Objects
Graded by reading your code against the checklist below.

What you build

  • Year(20160229) returns 2016
  • Month(20160229) returns 2
  • Day(20160229) returns 29
  • Encode(2016, 2, 29) returns 20160229
  • Use only /, %, * and +: no strings, no DateTime

Done means

All four methods use integer arithmetic only, and Encode reverses the other three.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. Year drops the month and day+20Everything is a number underneath
  2. Month divides, then keeps the remainder+25Everything is a number underneath
  3. Day keeps the last two digits+20Everything is a number underneath
  4. Encode puts the parts back+25Everything is a number underneath
  5. No strings and no DateTime+10Everything is a number underneath

What it teaches

The rest of From Procedures to Objects