Why do you say tha the scripts do not work? If you copy them into your browser and run them you will see that they do. Is the problem that you are passing the dates to the script in the wrong format?
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.