Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a problem with the following code...cud any one pls help me out in solving it.here is the code:declare @d1 datetime,@d2 datetimeset @d1='7/19/05'select @d2=getdate()if @d1=@d2begin print 'Both r equql'end else if @d1<@d2begin print 'D1 less than D2' endelse if @d1 > @d2begin print ' D1 greater than D2'endgowhen the dates are equal...i'm getting date is less....!d1 = 7/18/05getdate = 7/18/05 ....still i'm getting d1 is less tahn d2how to solve.
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2005-07-18 : 06:58:07
As as alternative, try this
declare @d1 datetime,@d2 datetimeset @d1='7/19/05'select @d2=getdate()if datediff(d,@d1,@d2)=0 beginprint 'Both r equql'end else if datediff(d,@d1,@d2)>0 beginprint 'D1 less than D2' endelse if datediff(d,@d1,@d2)<0 beginprint ' D1 greater than D2'endgo
MadhivananFailing to plan is Planning to fail
mmarovic
Aged Yak Warrior
518 Posts
Posted - 2005-07-18 : 10:01:08
getDate() returns date and time, so when you compare it with date without time it will almost certenly be different. Take a look at madhivanan's script.