In PHP out of the box is a powerful parser date:
So you can write this:
new \DateTime('first monday of this month'); // 2016-11-07
new \DateTime('first sunday of November 2016'); // 2016-11-06
same with dates manipulation, comparison, etc.
And how you can implement pogrugenie months when you click for example on 'next'button?
p.s. such things are easier to do entirely on the client. Not to mention the fact that it is better to take an existing calendar.