One of my favorite features of PHP is the
strtotime function. It takes a
string and gives you the equivalent time in return.
Unfortunately, there’s not something similar for other languages. There are other ATTEMPTS to duplicate the function, but nothing I’ve ran into that works quite as well.
With that, sometimes you need to get your hands dirty and write the logic out. Mother’s day falls on the second Sunday of May here in the states.
To start, you need to determine what day of the week May 1st falls on:
Now that we know what day of the week it falls on, we can calculate the first Sunday of the month:
So we know what the first Sunday date is, all we need to do is add another 7 days to that:
Now you have a Date object that is set to the second Sunday of May!