[英]Get month from date time now month, Get year from date time now year and write specific day
大家好,我想在今天之前從發票和客戶中搜索數據我正在使用DateDiff()GETDATE()函數,例如兩個表
1個客戶
- ID int
- Name Varcher
2張發票
- ID int
- ClientID int
- date Datetime
- Total money
詢問
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE DateDiff(dd, i.date, getdate()) = 0
當我運行查詢getdate()時,它是從日期時間獲取日期的功能,當我今天運行查詢時,日期內容為當前月份,當前年份和當前日期,日期為08-23-2010,而明天運行查詢的日期為日期是2010年8月24日。
Q-查詢執行的日期等於我要從日期時間現在月份中獲取月份的月份,從日期時間現在年份中獲取年份並僅寫特定的日期。
我不清楚您的問題,但據我了解,您希望時差不是0天。 然后,您將不得不使用其他日期部分( DateDiff()
第一個參數),有關詳細信息,請參見MSDateDiff文檔或DateAdd函數。
此外,也許您想使用
i.date between DateAdd(dd, -10, getDate) and getDate()
(它將顯示十天前到今天之間的所有內容)。
declare @day integer
select @day = 10
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE
DateDiff(dd, i.date, dateadd(dd,@day-datepart(dd,getdate()),getdate())) = 0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.