Blog Stats
  • Posts - 95
  • Articles - 0
  • Comments - 19
  • Trackbacks - 0

 

I Don't Care What Time It Is

Ever needed to-do this in SQL?

select * from ATABLE

where [SomeDate]=@A_DATE_YOU_WANT_TO_LOOKFO

Now suppose that you want to ignore times as SQL Server's DateTime object stores the time along with the date.

You can modify the query to-do just this.

select * from ATABLE

CAST(FLOOR(CAST( [SomeDate] AS float)) AS datetime) = @A_DATE_YOU_WANT_TO_LOOKFO

 

Obviously the variable @A_DATE_YOU_WANT_TO_LOOKFO should  have its time set to midnight,  but this works great.


Feedback

No comments posted yet.


Post a comment





 

 

 

 

Copyright © Richard Jones