What I can say? Have you tried to search this site?
Check it here:
http://www.sqlservercentral.com/Forums/Topic796803-338-1.aspx#bm796805
As I said, you don't need to create function for this, especially the one you have which unnecessary converts dates to all other data types...