Comparing results with today's date?

前端 未结 10 1698
情深已故
情深已故 2020-12-08 09:15

Is there a way to use the Now() function in SQL to select values with today\'s date?

I was under the impression Now() would contain the ti

相关标签:
10条回答
  • 2020-12-08 09:35

    You can try this sql code;

       SELECT [column_1], [column_1], ...    
        FROM (your_table)
         where date_format(record_date, '%e%c%Y') = date_format(now(), '%e%c%Y') 
    
    0 讨论(0)
  • 2020-12-08 09:37

    You can try:

    WHERE created_date BETWEEN CURRENT_TIMESTAMP-180 AND CURRENT_TIMESTAMP
    
    0 讨论(0)
  • 2020-12-08 09:38

    Not sure what your asking!

    However

    SELECT  GETDATE()
    

    Will get you the current date and time

    SELECT  DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
    

    Will get you just the date with time set to 00:00:00

    0 讨论(0)
  • 2020-12-08 09:38

    Just zero off the time element of the date. e.g.

    SELECT DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
    

    I've used GetDate as that's an MSSQL function, as you've tagged, but Now() is probably MySQL or you're using the ODBC function call, still should work if you just replace one with the other.

    0 讨论(0)
  • 2020-12-08 09:41

    If you have a table with just a stored date (no time) and want to get those by "now", then you can do this:

    SELECT * FROM tbl WHERE DATEDIFF(d, yourdate, GETDATE())=0
    

    This results in rows which day difference is 0 (so today).

    0 讨论(0)
  • 2020-12-08 09:41

    This worked for me:

    SELECT * FROM table where date(column_date) = curdate()
    
    0 讨论(0)
提交回复
热议问题