میتونی این تابع را تو C# پیاده ساری کنی
USE [xxx]
GO
/****** Object: UserDefinedFunction [dbo].[ShamsiDateDiff] Script Date: 12/15/2011 17:32:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[ShamsiDateDiff] (@PDate1 nvarchar(12),@PDate2 nvarchar(12))
RETURNS bigint
AS
BEGIN
DECLARE @ISLeap bit
DECLARE @EYear as Integer
DECLARE @EMonth as Integer
DECLARE @EDay as Integer
DECLARE @EAllDays as int
set @EYear= cast((substring(@PDate2 ,0,5))as int)
set @EMonth= cast((substring(@PDate2 ,6,2))as int)
set @EDay= cast((substring(@PDate2 ,9,2))as int)
DECLARE @SAllDays as int
DECLARE @SYear as Integer
DECLARE @SMonth as Integer
DECLARE @SDay as Integer
set @SYear= cast((substring(@PDate1 ,0,5))as int)
set @SMonth= cast((substring(@PDate1 ,6,2))as int)
set @SDay= cast((substring(@PDate1 ,9,2))as int)
select @EAllDays = case when @EMonth <=6
then (@EMonth-1)*31+@EDay
else case when @EMonth >6 and @EMonth<=12
then 6*31+ (@EMonth-7)*30+@EDay
end
end,
@SAllDays = case when @SMonth <=6
then (@SMonth-1)*31+@SDay
else case when @SMonth >6 and @SMonth<=12
then 6*31+ (@SMonth-7)*30+@SDay
end
end
declare @diff int
set @diff =@EAllDays-@SAllDays
declare @i int set @i =0
while @SYear+@i<@EYear
begin
select @diff= case
when dbo.IsLeap(@SYear+@i)=1
then @diff+366
else @diff+365
end
set @i=@i+1
end
Return @diff
end