我想从数据库中获取当前月份的周年日期,但我做不到。我的查询在下面给出,但它不起作用。
qry = "Select Anniversary_Date From Family_Information WHERE DATEADD(Year,DATEPART(Year, GETDATE()) - DATEPART(Year, Anniversary_Date),Anniversary_Date) >= GETDATE()";
我想从数据库中获取当前月份的周年日期,但我做不到。我的查询在下面给出,但它不起作用。
qry = "Select Anniversary_Date From Family_Information WHERE DATEADD(Year,DATEPART(Year, GETDATE()) - DATEPART(Year, Anniversary_Date),Anniversary_Date) >= GETDATE()";
WHERE
条款
SELECT...FROM...WHERE MONTH(now())=MONTH(GETDATE()) AND YEAR(now())=YEAR(GETDate())
应该工作 - 本月的周年纪念日。我不确定GETDATE()
它是什么?
怎么样
SELECT Anniversary_Date
FROM Family_Information
WHERE ((DATEPART(Year, GETDATE()) = DATEPART(Year, Anniversary_Date)
AND (DATEPART(Month, GETDATE()) = DATEPART(Month, Anniversary_Date))
尝试这个 ;
qry = "SELECT Anniversary_Date
FROM Family_Information
WHERE ((DATEPART(Year, GETDATE())) = DATEPART(Year, Anniversary_Date)
AND (DATEPART(Month, GETDATE())) = DATEPART(Month, Anniversary_Date))" ;