skip to Main Content

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

3

Answers


  1. 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
    
    Login or Signup to reply.
  2. It appears you are using SQL Server, so this should work:

    SELECT * FROM tables
    WHERE convert(varchar(10), time, 102) = convert(varchar(10), getdate(), 102)
    
    Login or Signup to reply.
  3. try to convert your time to the date format

    SELECT * FROM tables WHERE convert(time,getdate(), 101)  = CURDATE();
    

    More about date converting:
    https://tableplus.io/blog/2018/09/ms-sql-server-how-to-get-date-only-from-datetime-value.html

    https://www.mssqltips.com/sqlservertip/1145/date-and-time-conversions-using-sql-server/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search