[英]Get month from date time now month, Get year from date time now year and write specific day
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
when i run query the getdate() it is function to get date from date time now the date content current month and current year and current day when i run query today the date is 08-23-2010, when i run query tomorrow the date is 08-24-2010. 当我运行查询getdate()时,它是从日期时间获取日期的功能,当我今天运行查询时,日期内容为当前月份,当前年份和当前日期,日期为08-23-2010,而明天运行查询的日期为日期是2010年8月24日。
Q - the query do something equal date i want get month from date time now month, get year from date time now year and write specific day only. Q-查询执行的日期等于我要从日期时间现在月份中获取月份的月份,从日期时间现在年份中获取年份并仅写特定的日期。
I do not understand your question clearly, but as far as I understand you want to have a time difference other than 0 days. 我不清楚您的问题,但据我了解,您希望时差不是0天。 You would then have to use other dateparts (first argument to
DateDiff()
) See the MS documentation of DateDiff for details, or the DateAdd function. 然后,您将不得不使用其他日期部分(
DateDiff()
第一个参数),有关详细信息,请参见MSDateDiff文档或DateAdd函数。
Furthermore, maybe you want to use 此外,也许您想使用
i.date between DateAdd(dd, -10, getDate) and getDate()
(which would show everything between ten days ago and today). (它将显示十天前到今天之间的所有内容)。
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.