Date Range Query MySQL

后端 未结 5 1482
予麋鹿
予麋鹿 2020-12-18 15:09

I need a query to select data between two dates with today\'s date as a reference.

The database has a datetime field for \"start\" and a datetime field for \"end\".<

5条回答
  •  星月不相逢
    2020-12-18 15:53

    You can use the now timedate function in MySQL and the BETWEEN operator.

    Raw SQL:

    SELECT * FROM news
    WHERE NOW() BETWEEN start AND end;
    

    Note: Be mindful of the default timezone, which affects the NOW() function, used by the server providing your MySQL resource.

提交回复
热议问题