date comparison help

  • how to compare 2 dates but taking into consideration only the year and the month.

    ex. i have table t with test_date as column

    i want to : select * from t where t.test_date < getDate()

    but the comparison must be on month and year. For example t.test_date=2004/1 to be compared with 2005/1

    How's that?

  • SELECT *

    FROM t

    WHERE CONVERT(CHAR(6),t.testdate,112) < CONVERT(CHAR(6),getdate(),112)

  • I use this way,

    select * from t

    where year(testdate)*100+Month(testdate) < year(GetDate())*100+month(GetDate())

  • select * from t

    where DATEDIFF(m, testdate,  GetDate()) > 0

     

  • SELECT * from t Where year(t.testdate)=(year(getdate())-1) and month(t.testdate)=month(getdate())

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply