mysql 常用的時間日期函數小結

來源:互聯網
上載者:User

標籤:curd   rda   日期函數   date()   data   color   nbsp   name   星期六   

本文主要是總結一些常用的在實際運用中常用的一些mysql時間日期以及轉換的函數

1.now()  :返回當前日期和時間

select now();//2018-04-21 09:19:21

 

2.curdate()   :返回當前日期

select curdate();//2018-04-21 

 

3. dayofweek(data) : 返回日期 data 是星期幾

(1 = 星期日,2 =星期一...7=星期六,ODBC標準)

select dayofweek(‘2018-02-13’); // 3

 

4.weekday(date) : 返回日期 data 是星期幾

(0 = 星期日,1 =星期一...6=星期六,ODBC標準)

select WEEKDAY(‘1997-10-04 22:23:00‘);//5

 

5.dayofmonth(date) :返回date是一個月中的第幾天(1-31 範圍)

select dayofmonth(‘2018-04-21‘);//21

 

6.dayofyear(date) : 返回date是一年中的第幾天(1-366 範圍)

select dayofyear(‘2018-01-01‘);//1

 

7.month(date):返回date 中的月份值

select month(‘2018-04-21‘);//4

 

8.dayname(date):返回date 是星期幾(英文名返回)

select dayname(‘1998-02-05‘);//Thursday

 

9.monthname(date):返回date 是幾月(英文返回)

select monthname(‘2018-02-01‘)//February

 

10.quarter(date):返回date 是一年的第幾季度

select quarter(‘2018-04-21‘);//2

 

11.week(date,first):返回date 是一年的第幾周

(參數first:0表示周日是周的開始,1表示周一是周的開始,預設0)

select week(‘2018-02-20‘); // 7select week(‘2018-02-20‘,0); //7select week(‘2018-02-20‘,1); //8

 

12.year(date) : 返回date 中的年份(範圍1000-9999)

select year(‘98-02-03‘);//1998

 

 

未完。。。。。。

 

mysql 常用的時間日期函數小結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.