Link to home
Start Free TrialLog in
Avatar of thayduck
thayduckFlag for United States of America

asked on

Compare Dates not working

What I want to do, is start processing only if @testd = the last day of the month.
I searched and found different ways to calc the last day of the month.

Trouble is, it does not seem to work. Not sure what issue is.

Actually I want to used GetDate(), but am using @testd for testing reasons.


DECLARE @testd datetime
      set @testd = '2012-10-31 00:00:00.000'    
       
                 
           If   CONVERT(VARCHAR(10), @testd, 111)  =  CONVERT(VARCHAR(10),(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@testd)+1,0))), 111)         --Last day of month
               
                  Begin
SOLUTION
Avatar of Christopher Gordon
Christopher Gordon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Problem was the time element was different
Avatar of thayduck

ASKER

You guys were both right. (andycrofts code worked to)
My code was working, other programmer said there was data in test table and there wasn't .