I am such an idiot. It is dd for day of month, not DD. No surprise it was printing 366 and not 31 for the last day of the year. Excuse me while I garotte myself.