Write below user defined function,which will return varchar as:-
create function [dbo].[fn_Getdateonly] (@pinputdate datetime)
returns varchar(10)
begin
return cast(year(@pinputdate) as varchar(4)) + '/' +
cast(month(@pinputdate) as varchar(2)) + '/' +
cast(day(@pinputdate) as varchar(2));
end
To use above function,we will write:-
select dbo.fn_Getdateonly(Getdate());
Output:-2014/10/20 select dbo.fn_Getdateonly('2014-10-20'); Output:-2014/10/20 select dbo.fn_Getdateonly('10/20/2014');Output:-2014/10/20