Saturday, January 15, 2022

[FIXED] How to get data from database of current date

Issue

I want to get all data of current date from my database I'm using phpMyAdmin this is the query which I use but it did not show any data

SELECT * FROM tables WHERE time = CURDATE();

1


Solution

In SQL Server, you can do:

WHERE CONVERT(DATE, time) = CONVERT(DATE, time)

SQL Server is smart enough to use an index when converting a date/time to a date, so this is index-safe.

Your syntax is more reminiscent of MySQL. In that database, the best solution is:

WHERE time >= curdate() AND
      time < curdate() + interval 1 day


Answered By - Gordon Linoff

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.