如何使用 DateAdd 在单个字段中进行过滤

How to filter in a single field using DateAdd

"FollowingTrialDate"类型是日期时间

我想在单个字段中的日期之间进行过滤。

如何在 过去十五天 内的 FollowingTrialDate 字段中进行筛选。

如果有错误,错误在哪里?

此致,

SELECT C.[No],
convert(date,CaseDate,103) as ModuleDate,
convert(date,FollowingTrialDate,103) as FollowingTrialDate,
ShortDescription,
Username,
Name,
Surname,
Email,
C.[Description] as [Desc],
'Davalar' as ModuleName
FROM [LegalIT_MnemonicTEST].[dbo].[Module_Case] C 
inner join [System_User] su on C.LawyerID = su.UserID 
where CONVERT(date,FollowingTrialDate,0) 
between DATEADD(DD,-15,CONVERT(date,FollowingTrialDate,0)) and 
        DATEADD(DD,0,CONVERT(date,FollowingTrialDate,0)) 

试试下面的代码(如果 FollowingTrialDate 的类型是你的数据库中指定的日期时间)

请注意,如果您的 CaseDate 或 FollowingTrialDate 已经是数据库中指定的 'datetime' 类型,则您无需先将其转换为日期以用于输出或过滤 WHERE 子句中使用的数据

SELECT C.[No],
convert(datetime,CaseDate) as ModuleDate,
FollowingTrialDate,
ShortDescription,
Username,
Name,
Surname,
Email,
C.[Description] as [Desc],
'Davalar' as ModuleName
FROM [LegalIT_MnemonicTEST].[dbo].[Module_Case] C 
inner join [System_User] su on C.LawyerID = su.UserID 
where FollowingTrialDate
between DATEADD(DAY, DATEDIFF(DAY, 0, dateadd(dd, -15, getdate())), 0) and 
        DATEADD(DAY, DATEDIFF(DAY, 0, getdate()), 0)