mysql日期 時間函數集合(1/9)

來源:互聯網
上載者:User

下面的查詢選擇了所有記錄,其date_col的值是在最後30天以內:

mysql教程> select something from table
where to_days(now()) - to_days(date_col) <= 30;

dayofweek(date)
返回日期date的星期索引(1=星期天,2=星期一, ……7=星期六)。這些索引值對應於odbc標準。
mysql> select dayofweek('1998-02-03');
-> 3

weekday(date)
返回date的星期索引(0=星期一,1=星期二, ……6= 星期天)。
mysql> select weekday('1997-10-04 22:23:00');
-> 5
mysql> select weekday('1997-11-05');
-> 2

dayofmonth(date)
返回date的月份中日期,在1到31範圍內。
mysql> select dayofmonth('1998-02-03');
-> 3

dayofyear(date)
返回date在一年中的日數, 在1到366範圍內。
mysql> select dayofyear('1998-02-03');
-> 34

month(date)
返回date的月份,範圍1到12。
mysql> select month('1998-02-03');
-> 2

dayname(date)
返回date的星期名字。
mysql> select dayname("1998-02-05");
-> 'thursday'

monthname(date)
返回date的月份名字。
mysql> select monthname("1998-02-05");
-> 'february'

quarter(date)
返回date一年中的季度,範圍1到4。
mysql> select quarter('98-04-01');
-> 2

week(date)
 
week(date,first)
對於星期天是一周的第一天的地方,有一個單個參數,返回date的周數,範圍在0到52。2個參數形式week()允許
你指定星期是否開始於星期天或星期一。如果第二個參數是0,星期從星期天開始,如果第二個參數是1,
從星期一開始。
mysql> select week('1998-02-20');
-> 7
mysql> select week('1998-02-20',0);
-> 7
mysql> select week('1998-02-20',1);
-> 8 

首頁 1 2 3 4 5 6 7 8 9 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.