How to select last 30 days dates in MySQL?

netdjw

Can I list somehow the dates of last 30 days in MySQL? Not from a table!

For example I think about like this:

SELECT date WHERE date BETWEEN SUBDATE(NOW(), INTERVAL 30 DAY) AND NOW();

Is that possible?

The Blue Dog

I hacked this together from someone else's code, but it seems to work:

SELECT DATE_FORMAT(m1, '%d %b %Y')
FROM (
SELECT SUBDATE( NOW() , INTERVAL 30 DAY) + INTERVAL m DAY AS m1
FROM (
select @rownum:=@rownum+1 as m from
(select 1 union select 2 union select 3 union select 4) t1,
(select 1 union select 2 union select 3 union select 4) t2,
(select 1 union select 2 union select 3 union select 4) t3,
(select 1 union select 2 union select 3 union select 4) t4,
(select @rownum:=-1) t0
) d1
) d2 
WHERE m1 <= now()
ORDER BY m1

The original code by valex is here:

How to get a list of months between two dates in mysql

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

DateADD with codeigniter, to get the entry of the last 30 days

분류에서Dev

Best practice: Number of views/clicks over the last 30 days

분류에서Dev

How to count fractional days between 2 dates

분류에서Dev

Select the last entry recorded in a table for each day, within a duration of days

분류에서Dev

how to receive all days between 2 dates in laravel

분류에서Dev

How many days between two dates are in a certain month?

분류에서Dev

How do I select users that have not had their score updated within the last 2 hours or at all using Mysql

분류에서Dev

30 분 차이가있는 MySql Select 행

분류에서Dev

How to get difference between 2 dates in number of days,hours,minutes and seconds

분류에서Dev

MySQL-SELECT * WHERE Dates 작동, SELECT specific & INNER JOIN WHERE Dates 작동하지 않음

분류에서Dev

MySQL Select Last Entry for each User, than the next entry

분류에서Dev

MYSQL SELECT 문 Where last Date If Trace = 12

분류에서Dev

MySQL: select all the data but if contains ' * ', then show the last four characters

분류에서Dev

Elapsed days between two dates always giving one days difference

분류에서Dev

두 날짜 사이의 MySQL SELECT 분 (DIFFERENT DAYS)

분류에서Dev

Calculating the days between two given dates

분류에서Dev

PHP, identify dates and week days in strings

분류에서Dev

MySQL -- Select year from a format like "2010-07-30 22:58:59"

분류에서Dev

Mysql how to group by each day between two dates?

분류에서Dev

select multiple dates by dragging over datepicker dates

분류에서Dev

PHP MySQL dates not working

분류에서Dev

Dates sort mysql results

분류에서Dev

how do i get last result in group by MySQL query (not the first)

분류에서Dev

how to select all tables with certain postfix in mysql?

분류에서Dev

How can i get last week, current week and last month record from mysql

분류에서Dev

Generate month end dates for last 12 months

분류에서Dev

Linq-to-Sql filtering for dates of last element

분류에서Dev

Number of working days between 2 dates according JIRA's configuration

분류에서Dev

Selecting dates 3 days before now on Android with SQLite

Related 관련 기사

  1. 1

    DateADD with codeigniter, to get the entry of the last 30 days

  2. 2

    Best practice: Number of views/clicks over the last 30 days

  3. 3

    How to count fractional days between 2 dates

  4. 4

    Select the last entry recorded in a table for each day, within a duration of days

  5. 5

    how to receive all days between 2 dates in laravel

  6. 6

    How many days between two dates are in a certain month?

  7. 7

    How do I select users that have not had their score updated within the last 2 hours or at all using Mysql

  8. 8

    30 분 차이가있는 MySql Select 행

  9. 9

    How to get difference between 2 dates in number of days,hours,minutes and seconds

  10. 10

    MySQL-SELECT * WHERE Dates 작동, SELECT specific & INNER JOIN WHERE Dates 작동하지 않음

  11. 11

    MySQL Select Last Entry for each User, than the next entry

  12. 12

    MYSQL SELECT 문 Where last Date If Trace = 12

  13. 13

    MySQL: select all the data but if contains ' * ', then show the last four characters

  14. 14

    Elapsed days between two dates always giving one days difference

  15. 15

    두 날짜 사이의 MySQL SELECT 분 (DIFFERENT DAYS)

  16. 16

    Calculating the days between two given dates

  17. 17

    PHP, identify dates and week days in strings

  18. 18

    MySQL -- Select year from a format like "2010-07-30 22:58:59"

  19. 19

    Mysql how to group by each day between two dates?

  20. 20

    select multiple dates by dragging over datepicker dates

  21. 21

    PHP MySQL dates not working

  22. 22

    Dates sort mysql results

  23. 23

    how do i get last result in group by MySQL query (not the first)

  24. 24

    how to select all tables with certain postfix in mysql?

  25. 25

    How can i get last week, current week and last month record from mysql

  26. 26

    Generate month end dates for last 12 months

  27. 27

    Linq-to-Sql filtering for dates of last element

  28. 28

    Number of working days between 2 dates according JIRA's configuration

  29. 29

    Selecting dates 3 days before now on Android with SQLite

뜨겁다태그

보관