Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Just the date of a datetime
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01287635
Message ID:
01287640
Views:
11
>There has to be an easier way to compare just the date of two datetime objects. I found DATEONLY in BOL and was very happy until I tried it and found it was for report builder.
>
>Consider this:
>
>IF (YEAR(@Date1) = YEAR(@Date2) AND MONTH(@Date1) = MONTH(@Date2) AND DAY(@Date1) = DAY(@Date2)) BEGIN
>	PRINT 'Same date (I do not care what time it is)'
>END ELSE BEGIN
>	PRINT 'Different date'
>END
>
>
>Is there a way to make the IF argument a lot shorter?
>
>Thanks,
>Einar
IF CONVERT(varchar(8), @Date1, 112) = CONVERT(varchar(8), @Date2, 112)
   ---
ELSE
  ---
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform