sql date select

select * from
yourtable where yourDateColumn < '2012-12-8' and yourDateColumn >= '2012-12-07'

You can use BETWEEN to compare the dates:

select *
from yourTable
where yourDate between '2012-07-12' and '2012-08-12'

Or if you are looking for one date in particular you can use. You can change the '2012-07-12' to a parameter that could be passed in so you could get any date:

select *
from yourTable
where Cast(datediff(day, 0, yourDate) as datetime) = '2012-07-12'

I think that the Julius is asking how to get only rows with 7/12/2012 17:21:33

So I can offer you one solution that is proven to be right:

1) Take a look at T-SQL Convert function at T-SQL Convert function

2) When you will look at that take note on conversion codes

Convert codes

Image source: http://technet.microsoft.com/en-us/library/ms187928.aspx

And now when I annoyed everybody with the theory here is the code:

For europe

select * from table_name
where convert(varchar, column_that_has_date_in, 104) = '12.07.2012'

For US

select * from table_name
where convert(varchar, column_that_has_date_in, 101) = '07/12/2012'

And one other thing worth mentioning is why when we type in sql statement we get 0 rows:

select * from table_name
where column_that_has_date_in like '%07/12/2012%'

This is because the query is looking only for dates with NO TIME portion.

Tags:

Sql

Date