Week list for the current date in PHP

This post shows two examples of how to find the week list for the current date. Input parameter is date, and the output is date list from Monday till Sunday. First example is done with classic algorithm while second example uses ISO week date format.

Date shift in JavaScript

Date shift in JavaScript can be done by counting days of the month and thinking of 28 or 29 days in February. Don’t forget the year. This is a long and complicated algorithm. I suggest a simpler solution. Transform date to the number of milliseconds, and make easy arithmetic with integers. After addition and subtraction, create date from the milliseconds.

JavaScript date validation

JavaScript date validation can be done in many ways like month range testing, day range testing (depending on number of days in the month) and so on. Here is shown much simpler solution. Take day, month and year from input string to create JavaScript Date object. Compare input day, month and year with day, month and year extracted from the Date() object. If they aren’t the same then the input date is not valid.