简体   繁体   English

从日期时间开始的当前月份和当前年份的特定日期

[英]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.

相关问题 当前月份和年份的特定日期 - Specific day of current month and year 如何通过保留月份和日期并将Year更改为当前来选择SQL日期? - How to select SQL date by keeping Month and day and changing Year to current? 在 sql server2005 中使用 sql 查询从当前日期的出生日期查找年份中的年龄? - find age in year from date of birth from current date using sql query in sql server2005? 什么SQL Server语句以获取忽略当前年份的日期和月份? - What is SQL Server statement to get day and month ignoring the current year? 我怎样才能得到从当天,当月或当年的第一天到当天的一周,一个月或一年的日期? - How could I get the the date of the week, month or year starting from the first day up to the current day of the current week, month or year? 用于选择从昨天的特定日期/时间到当天的特定日期/时间的范围的 SQL 查询 - SQL query to select range from specific date/time yesterday to specific date/time current day MYSQL从当前年份,当前月份和一周中的变量日期获取日期 - MYSQL Get the date from the current year, current month and variable day of the week SQL 统计从日期开始到当前月/年的数据 - SQL count data from beginning of the date till current month/year 将日期拆分为年月日 SQL 服务器 - splitting date into year month day SQL server 在sql server中将年月日转换为日期 - Converting year month day to date in sql server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM