How to Get Day of Week from any date
Hanan Hamza

Hanan Hamza @whatthehanan

About: Full Stack Developer - [Typescript,Scala] Using Dev.to as sort of a diary for technical stuff

Location:
Pakistan
Joined:
Apr 20, 2019

How to Get Day of Week from any date

Publish Date: Jul 16 '22
1 0

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

Comments 0 total

    Add comment