年月日:如2014-04-25 08:00:00
截取時間中的日:取出來25,
可以使用date_format這個函數取,如圖:
相應的date_format函數使用方法可以參考下:
http://www.w3school.com.cn/sql/func_date_format.asp
當截取日期的時候如果使用substring,left,right,substring_index 這些函數都取不出來25,下邊介紹它們的區別:
1、從左開始截取字符串
left(str, length)
說明:left(被截取字段,截取長度)
例:select left(content,200) as abstract from my_content_t
2、從右開始截取字符串
right(str, length)
說明:right(被截取字段,截取長度)
例:select right(content,200) as abstract from my_content_t
3、截取字符串
substring(str, pos)
substring(str, pos, length)
說明:substring(被截取字段,從第幾位開始截取)
substring(被截取字段,從第幾位開始截取,截取長度)
例:select substring(content,5) as abstract from my_content_t
select substring(content,5,200) as abstract from my_content_t
(注:如果位數是負數 如-5 則是從后倒數位數,到字符串結束或截取的長度)
4、按關鍵字截取字符串
substring_index(str,delim,count)
說明:substring_index(被截取字段,關鍵字,關鍵字出現的次數)
例:select substring_index(”blog.chinabyte.com”,”。”,2) as abstract from my_content_t
結果:blog.chinabyte
(注:如果關鍵字出現的次數是負數 如-2 則是從后倒數,到字符串結束)