SQL date picker

I want to be able to select all rows in the database where the month and year match what I'm looking for. Since the DATE field has a year, a month, and a day, how do I search for a year and a month?

+3
source share
6 answers
SELECT *
FROM myTable
WHERE ( YEAR(myfield) = '2009')
  AND ( MONTH(myfield) = '1')
+3
source
SELECT * 
FROM tblTableName 
WHERE Month(ColumnDate) = Month(MyDate) 
    AND Year(ColumnDate) = Year(MyDate)
+6
source

, , , .

:

select SomeField
from SomeTable
where SomeDate >= ? and SomeDate < ?

( , , seond .)

: ( #)

DateTime start = new DateTime(date.Year, date.Month, 1)
DateTIme end = start.AddMonths(1);
+3

MySQL:

SELECT *
FROM   mytable
WHERE  date >= STR_TO_DATE(CONCAT(EXTRACT(YEAR_MONTH FROM @mydate), '01'), '%Y%m%d')
   AND date < STR_TO_DATE(CONCAT(EXTRACT(YEAR_MONTH FROM @mydate), '01'), '%Y%m%d') + INTERVAL 1 MONTH

date.

+2

, . IN SQl Server

where year(datefield) = @year and month (datefield) - @month 

.

or you can create a where clause by creating a date range

where the date field is between 20090101 and 20090201

+1
source

You want to use MONTH () and YEAR () in mysql.

0
source

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


All Articles