[英]Specific day of current month and current year from date time SQL Server 2005
Hello everyone i want search data from invoices and client by today date I'm using DateDiff() GETDATE() functions for example two tables 大家好,我想在今天之前从发票和客户中搜索数据,我使用DateDiff()GETDATE()函数作为示例,例如两个表
1 Client 1个客户
- ID int
- Name Varcher
2 Invoice 2张发票
- ID int
- ClientID int
- date Datetime
- Total money
query 询问
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE DateDiff(dd, i.date, getdate()) = 0
I want select query by specific day of current month and current year from date time if the current month is 08 and current year 2010 i want write any day of month Thanks every one help me 如果当前月份是08且当前年份是2010,我想按日期月份和当前年份的特定日期选择查询,我想写每月的任何一天, 谢谢大家的帮助
here is one way which will also be able to use an index 这是一种也可以使用索引的方法
where i.date >= DATEADD(Day, DATEDIFF(Day, 0, GETDATE()), 0)
and i.date < DATEADD(Day, DATEDIFF(Day, 0, GETDATE()), 1)
The simplest way to select records from a specific day in the current month and year is to declare a datetime variable assigned to the specified day, month and year, and replace getdate()
in your query with the variable - like so: 从当前月份和年份中特定日期选择记录的最简单方法是声明一个分配给指定日期,月份和年份的datetime变量,然后用该变量替换查询中的getdate()
,如下所示:
declare @date datetime
select @date = '10-Aug-2010'
Select * from client c
inner join invoice i on c.id = i.ClientID
WHERE DateDiff(dd, i.date, @date) = 0
EDIT: To run a query for a specified day of the month in the current month, try the following: 编辑:要在当月的当月指定日期运行查询,请尝试以下操作:
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.