如:2007-08-09 20:20:02
返回结果 起始时间:2007-08-01 00:00:00
------解决方案--------------------
declare @date datetime
set @date= '2007-08-09 20:20:02 '
select cast(convert(char(8),@date,120)+ '01 ' as datetime),dateadd(ss,-1,convert(char(8),dateadd(mm,1,@date),120)+ '01 ')
/*
------------------------------------------------------ ------------------------------------------------------
2007-08-01 00:00:00.000 2007-08-31 23:59:59.000
*/
------解决方案--------------------
好象需要修改下
declare @date datetime
set @date= '2007-08-09 20:20:02 '
select cast(convert(char(8),@date,120)+ '01 ' as datetime),dateadd(ss,-1,convert(char(8),dateadd(mm,1,@date),120)+ '01 ')
------解决方案--------------------
declare @date datetime
set @date= '2007-8-9 '
select convert(datetime,convert(char(07),@date,120)+ '-01 '),
dateadd(second,-1,dateadd(month,1,convert(char(07),@date,120)+ '-01 '))
------------------------------------------------------ ------------------------------------------------------
2007-08-01 00:00:00.000 2007-08-31 23:59:59.000