-1

I have a little problem with my SQL Query:

I have this value on my table: 2014-10-23 00:00:00

I have a record like this each 2 minutes every day, and I need to SELECT all the value of today.

Now I made this:

WHERE mytable.data LIKE CURDATE()

and it doesn't work. I tried a lot of things found here on stackoverflow and nothing could help me. Thanks for answer.

Tony
  • 9,672
  • 3
  • 47
  • 75

1 Answers1

1

You don't say which version of SQL Server you are using, if you have the DATE data type available you can cast the datetime returned by getdate() or CURRENT_TIMESTAMP to strip off the time part.

But then you need a range to find all the matching rows, something like:

SELECT *
FROM mytable
WHERE mytable.data >= CAST(GETDATE() AS date)
  AND mytable.data < CAST(DATEADD(day, 1, GETDATE()) AS date)

SQL Fiddle

Tony
  • 9,672
  • 3
  • 47
  • 75