Click here to Skip to main content
16,018,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT COUNT(id)
FROM tableA
WHERE DATE(getdate) = '2016-08-14'


The getdate datatype is datetime but right now I only want date only.

The error that I got is

Error in WHERE clause near '('.
Error in WHERE clause near ' '.
Unable to parse query text.

What I have tried:

I have tried using all the solution here but it still not working
http://stackoverflow.com/questions/6119369/simple-datetime-sql-query[^]
Posted
Updated 8-Oct-16 3:57am
v6
Comments
Maciej Los 8-Oct-16 5:30am    
What database: SQL server, MySQL, PostgreSQL, Oracle?

Assuming Microsoft SQL Server, try something like this:
SQL
DECLARE @TheDate date = '20160814';

SELECT COUNT(id)
FROM tableA
WHERE getdate >= @TheDate
AND getdate < DateAdd(day, 1, @TheDate);
 
Share this answer
 
If you look at this link http://www.w3schools.com/sql/sql_dates.asp[^] , you will see that your date as a string is in wrong format.
try: 2016-10-08

Site to help you to learn SQL: http://www.w3schools.com/sql/default.asp[^]

[Update]
You should learn SQL properly !
getdate and GETDATE() are not the same thing !
http://www.codeproject.com/script/Answers/Post.aspx?aid=1137143[^]
 
Share this answer
 
v2
Comments
Member 12154788 8-Oct-16 4:01am    
i have tried but not working
David_Wimbley 8-Oct-16 10:31am    
Instead of saying "i have tried but not working" you should indicate what is not working and what you expect it to do. If you want help, explain things clearly so those that are willing can help you understand your issue.

Right now GETDATE() is pretty self explanatory. SELECT GETDATE().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900