• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 36
  • Last Modified:

Date in WHERE CLAUSE

Hi,

The data type is DateTime.

I am trying to just filter by DATE. Is there a way to do this? thanks
0
mcrmg
Asked:
mcrmg
1 Solution
 
Bill PrewCommented:
What Database are you working with, Oracle, MySql, SQL Server, Access, ... ?


»bp
0
 
mcrmgAuthor Commented:
I am using SQL..Thanks
0
 
Ryan ChongCommented:
i guess you mean MS SQL?
if yes then try use cast function, like:

where cast(yourDateTime as date) = '2018-01-23'

Open in new window


SQL Cast Date
http://sqlserverplanet.com/tsql/cast-date
0
 
mcrmgAuthor Commented:
that works well..thank you
0
 
_agx_Commented:
If there's an index on the datetime column, a slightly more index friendly approach is:

where yourDateTime >= '2018-01-23'  -- filter day
and     yourDateTime < '2018-01-24'  -- day AFTER
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now