user8340125
user8340125

Reputation:

Select date from SQL Server table

How do I select the date from a table in SQL Server?

I want:

select *
from TABLE
where TICKET_DATE between 01/01/2016 and 12/31/2016. 

In Oracle it is easy using to_date, how do I do it in SQL Server? Below is how the date column is formatted. I do not care about time.

2016-07-14 20:04:50.000
2016-07-29 09:49:05.000
2016-07-18 21:22:51.000
2016-07-03 07:56:15.000

Upvotes: 2

Views: 64

Answers (1)

Siyual
Siyual

Reputation: 16917

You can just use CONVERT() to cast it as a DATE.

Select Convert(Date, Ticket_Date)
From   TABLE
Where  Ticket_Date Between '2016-01-01' And '2016-12-31'

If you just want things from a particular date, you can do this instead:

Select *
From   TABLE
Where  Convert(Date, Ticket_Date) = '2016-07-14'

Upvotes: 2

Related Questions