搜尋此網誌

2014年10月25日 星期六

MySQL常用函數

now()
當前日期時間(yyyy-MM-dd HH:mm:ss)

curdate()

當前日期(yyyy-MM-dd)

curtime()

當前時間(HH:mm:ss)
date()
顯示時間的日期部分

extract(xxx from date)
提取時間的單獨部分,如:年,月,日
(xxx參考表http://www.w3school.com.cn/sql/func_extract.asp)

date_add(時間, interval 數字(可為負數) xxx)
date_sub(時間, interval 數字(可為負數) xxx)
對指定的時間做調整
(xxx參考表http://www.w3school.com.cn/sql/func_date_add.asp)

datediff(結束日期, 開始日期)
返回兩日期相差的天數

date_format(時間, xxx)
時間以指定的格式顯示
(xxx參考表http://www.w3school.com.cn/sql/func_date_format.asp)

select * from table order by cast(field as unsigned)
將字串當作數字排序

沒有留言:

張貼留言