SQL语句中日期的计算方法大全 (4)

select * from salesmb
select count(*) from salesdreport where employeeid=\'11\'and productsid=\'7\' and (updatetime between \'2006-8-1 00:00:00\'and \'2006-8-30 00:00:00\') --销售数量
select sum(sales) from salesmb where eid=\'11\'and productsid=\'7\' and (mbrq between \'2006-8-1 00:00:00\'and \'2006-8-30 00:00:00\') --目标数量

select dateadd(d,-day(getdate()),getdate())

select cast(year(getdate()) as nvarchar)+\'-\'+cast(month(getdate()) as varchar)+\'-1 00:00\'
select cast(year(getdate()) as nvarchar)+\'-\'+cast(month(getdate()) as varchar)+\'-\'+cast(day(getdate()) as varchar)

select dateadd(m,1,dateadd(d,-day(getdate()),getdate()))


select dateadd(m,1,getdate())

===============================================================================================================================


select getdate()
select dateadd(d,1,dateadd(d,-day(getdate()),getdate()))+"00:00"

declare @sdate smalldatetime
select cast(year(getdate()) as nvarchar)+\'-\'+cast(month(getdate()) as varchar)+\'-1 00:00\'
select @sdate
select dateadd(day,-1,dateadd(Month,1,@sdate))

select cast(year(getdate()) as nvarchar)+\'-\'+cast(month(getdate()) as varchar)+\'-1 00:00\'

select dateadd(d,-day(getdate()),getdate())

select dateadd(day,-1,dateadd(Month,1,cast(year(getdate()) as nvarchar)+\'-\'+cast(month(getdate()) as varchar)+\'-1 00:00\'))

select dateadd(d,-day(getdate()),getdate())

select dateadd(d,1,dateadd(d,-day(getdate()),getdate()))
select dateadd(m,

SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
SELECT dateadd(ms,0,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zypwys.html