I modified the code to suit my date format which is yyyy-mm-dd and it works fine except that if the current date is 2008-04-01 the new date is 2008-03-31 instead of 2008-03-29, where have I gone wrong please?
The code is working fine. I suspect that "where you have gone wrong" is in confusing March and February. If "today" is the first day of the fourth month, that is, the first of April, then "yesterday" is the last day of March, which has thirty-one days (every year).
If the current date were 2008-03-01 (The first of March, the third month of the year) then yesterday, since 2008 is a leap year, would be the twenty-ninth day of February, 2008-02-29.
Here is a little rhyme which, if you learn it, may help you avoid this (evidently) tricky problem...
Thirty days hath September,
April, June, and November:
All the rest have thirty-one,
Except for February
Which hath but twenty-eight days clear,
And twenty-nine in each leap year.