How to loop through days (dates) in bash and force two digits (zerofill)

Often with bash, I need to run a script and pass in a date. It helps to be able to use a bash loop to do it all at once. Here’s how you do it, and make sure the day is two digits. Note the use of the println command.

for day in {1..31}; do php some_script.php 2011-05-`printf "%02d" $day`; done