Calculating This Week’s Dates with JavaScript
If you ever need to work with dates in JavaScript and you’re used to PHP (or just about anything else), you’re in for a challenge. Dates in JS are hard. I was recently working on something where I had to display the dates of the current week on a page. Sounds easy, right? This was a WordPress site, and would’ve been trivial in PHP, but for a number of reasons I had to use JS instead.
Long story short, you end up having to do some things that PHP’s date functions do for you. Spoiler alert, it involves calculations and some making your own arrays of date names. There are libraries out there that make working with dates in JS a lot easier, but in this case it wasn’t worth using one of those.