/****** Object:  UserDefinedFunction [dbo].[FarkiBul]    Script Date: 7.04.2016 21:48:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
ALTER FUNCTION [dbo].[FarkiBul](@t datetime)

RETURNS nvarchar(100)
AS
BEGIN
DECLARE @s INT
DECLARE @m VARCHAR(35)

SET @s=DATEDIFF(s,getdate(),@t);

IF @s>= 31536000
BEGIN
return CONVERT(nvarchar, @s/31536000) + ' Yıl Sonra';
END;

IF @s>= 2592000
BEGIN
return CONVERT(nvarchar, @s/2592000) +' Ay Sonra';
END;

IF @s>= 604800
BEGIN
return CONVERT(nvarchar, @s/604800) + ' Hafta Sonra';
END;

IF @s>=86400 
BEGIN
return CONVERT(nvarchar, @s/86400) + ' Gün Sonra';
END;

IF @s>=3600 
BEGIN
return CONVERT(nvarchar, @s/3600) + ' Saat Sonra';
END;

if @s>=60
BEGIN
return CONVERT(nvarchar, @s/60) + ' Dakika Sonra';
END;

if @s<=60
BEGIN
set @m= ' Şuan';
END;

return @m;
END