Color of the Day

Comparing hexadecimal numbers with dates, you can see it’s possible to use a 6-digits hexadecimal number representing a day. The year fits in 3 digits (<=4.096); month fits in 1 digit (16) and day in 2 (256, but we need only 31). It’s the same as a HTML color!

For example: today, 23th august. 2021 in hexadecimal is 7E5; august is 8; 23 in 16-base is 17. So, the color for today is #7E5817.

Thinking about, I made a PHP function 10 years ago. It returns a color for a given day. It’s like:

function daycolor($date) {
    $dts = strtotime($date);
    $y = dechex(date("Y", $dts));
    $m = dechex(date("n", $dts));
    $d = dechex(date("d", $dts));
    if (strlen($d) < 2) {
        $d = "0" . $d;
    }
    $dc = "#$y$m$d";
    return $dc;
}

It’s a very simple code, easy to convert to any other language. Unfortunately, the colors come too similar, changing overly slow..

Comment

Your email address will not be published. Required fields are marked *

Vivaldi