我正试图从2010年12月31日到2011年12月31日每14天返回一次,但此声明似乎不起作用
SELECT DISTINCT
Convert(varchar,Month(Time_Stamp)) + '/' +
Convert(varchar,DAY(Time_Stamp))
FROM Report
WHERE Time_Stamp LIKE '%2011%' AND
Convert(varchar(20),DATEDIFF(D,'2010-12-31',Time_Stamp) / 14) NOT LIKE '%.%'
ORDER BY 1
这似乎不起作用,因为它会返回古怪的日期......
1/1
1/10
1/11
每14天应该返回一次,就像这样......
1/14
1/28
2/11
依旧......
任何人都知道一种更干净的方法,它确实有用吗?
答案 0 :(得分:1)
更改模数值以偏移开始日期
SELECT DISTINCT
Convert(varchar,Month(Time_Stamp)) + '/' +
Convert(varchar,DAY(Time_Stamp))
FROM Report
WHERE
Time_Stamp LIKE '%2011%'
AND
DATEPART(dayofyear, Time_Stamp) % 14 = 0
ORDER BY 1