关于日期的一个sql语句
表 m_test的数据如下
mon limitDay
7 2007/01/04
3 2007/03/09
6 2006/09/12
我要取得
当前日期的月份(getdate())-mon字段的月份 的日期 <=limitDay 的数据。该如何写?
select year(getdate()) as ye,month(getdate())-m_test.mon as mon,day(getdate()) as [day] from m_test
------解决方案--------------------select dateadd(mm,mon,getdate()) as [day] from m_test
------解决方案--------------------mon limitDay
7 2007/01/04
3 2007/03/09
6 2006/09/12
select * from 表 where dateadd(mm,getdate,-mon) <limitDay
------解决方案--------------------select * from test where dateadd(month,-mon,limitDay) <=limitDay
------解决方案--------------------where limitDay> =dateadd(month,-mon,getdate())
------解决方案--------------------select * from 表 where dateadd(mm,-mon,getdate()) <limitDay
-_-}
------解决方案--------------------create table m_test
(
mon int,
limitday datetime
)
insert into m_test
select 7, '2007/01/04 '
union all select 3, '2007/03/09 '
union all select 6, '2006/09/12 '
select * from m_test where convert(varchar(10),limitday,120)> =dateadd(mm,-mon,getdate())