DEV Community

Hanan Hamza
Hanan Hamza

Posted on

1

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay