Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Compare datetime variables only to check date

Total Hit ( 3801)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
--//Demo: How to compare datetime variables to check only date (not time)
--//Use :
--// If LEFT( CONVERT(varchar, @dt1, 120), 10) = LEFT( CONVERT(varchar, @dt2, 120), 10)
--//  print 'equal'
--// else
--//  print 'equal'

declare @dt1 datetime
declare @dt2 datetime

set @dt1='2003-10-06 13:17:29.327' --//getdate()    
set @dt2='10/6/03' --//This should be the current date

--// compare datetime variables for same date (Wont Work)
If @dt1=@dt2
   Print '[Test1] Both dates are equal'
else
   Print '[Test1] Both dates are not equal'

--// compare datetime variables for same date (Will Work)

If LEFT( CONVERT(varchar, @dt1, 120), 10) =LEFT( CONVERT(varchar, @dt2, 120), 10)
   Print '[Test2] Both dates are equal'
else
   Print '[Test2] Both dates are not equal'



--select getdate()


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.