I put some debug strings and the date appears as follows:
adate is 2007-01-01, atime is 12:00:00 , i had the wrong format before...
I will try out the above. Is the --$month right to use?
I'd use $month-1, since there's no reason to modify $month in the process. The subtraction is required since timelocal expects a 0-based month (Jan = 0).