MySQL to select specific DATETIME values?

Right now I have a MySQL table with one column named "date_time", which simply lists the different DATETIME values ​​(for example, "2010-11-30 12:55:00"). Is it possible to build a query directly:

  • Selects DATETIME values, where is the current month?
  • Selects DATETIME values ​​where days do not pass (for example, tomorrow and before the end of the month?

An abstract query in my mind would look like this:

$query = "SELECT * FROM meetings WHERE uid = " . $_SESSION['uid'] . "AND the DATETIME month is active month AND the DATETIME day is bigger than the active day"

Is this feature possible in MySQL (some searches, but haven’t found anything useful), or will I have to use the PHP functions later to filter this stuff out? Thank you very much in advance.

+3
source share
2

- :

$query = "SELECT * FROM meetings WHERE uid = " . $_SESSION['uid'] . "WHERE EXTRACT(month from now()) = extract(month from date_time) AND EXTRACT(day from now()) < extract(day from date_time)

+1

MySQL , :

...

SELECT ... WHERE MONTH(date_time) = MONTH(now());

:

SELECT ... WHERE DAY(date_time) > DAY(now());

, / . , .

+5

Source: https://habr.com/ru/post/1775393/


All Articles