DEV Community

Hanan Hamza
Hanan Hamza

Posted on

How to Get Day of Week from any date

3 charts to remember

Week chart

Week Chart

Month chart

Month Chart

Century chart

Century Chart

The Trick

take any date e.g 15 aug, 2050, now to get the day of week for any date there are two main steps:

  • Addition

    • Take the actual date (15 in our case)
    • Take the value of month from Month chart (2 in our case)
    • Take value from century chart (6)
    • Take last 2 values from the year (50)
    • Take whole number from the result of (last 2 values from year) / 4 (12 in our case)

sum all the numbers: 15 + 2 + 6 + 50 + 12 = 85

  • Modulus
    • sum % 7 = 1
    • get value from week chart = Monday

Exception

  • if the year is a leap year and the month is Jan or Feb subtract 1 from the sum in first step

Reference

Youtube
Link

Top comments (0)