Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 all records with in month

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-26 : 08:09:19
SAM writes "I want all records which has date with in last month. I i am using datediff it either take days part or month but ignores year iwant last month with in say 12/9/2004 - 12/6/2004"

dsdeming

479 Posts

Posted - 2003-09-26 : 09:18:56
How are you using datediff? When I do this, it works just fine:

set nocount on
create table #a( MyDate datetime )
insert into #a select getdate()
insert into #a select '8/19/2003'
insert into #a select '8/30/2003'
insert into #a select '8/30/2002'

select * from #a where datediff( mm, MyDate , getdate() ) = 1

drop table #a

If datediff ignored the year, the 8/30/2002 date would be returned.

Dennis
Go to Top of Page
   

- Advertisement -