the problem is in your calling to the function...
select * from fn(41,'01/01/2011','2011/01/31')
date you have passed
'01/01/2011'
is successfully converted to datetime
SELECT convert(datetime,'01/01/2011')
but the date
'2011/01/31'
is not able to converted to datetime
SELECT convert(datetime,'2011/01/31')
for getting resolve your issue your need to call your funcation like this...
select * from fn(41,'01/01/2011','01/31/2011')
to know more about datetime conversion and its formats please review the link..
http://www.sqlusa.com/bestpractices/datetimeconversion/[
^]