SQL時間日期總結

2021-10-09 11:28:45 字數 645 閱讀 6292

1.時間型別

datetime 8 bytes yyyy-mm-dd hh:mm:ss 1000-01-01 00:00:00 ~ 9999-12-31 23:59:59

timestamp 4 bytes yyyy-mm-dd hh:mm:ss 1970-01-01 00:00:01 ~ 2038

date 3 bytes yyyy-mm-dd 1000-01-01 ~ 9999-12-31

year 1 bytes yyyy 1901 ~ 2155

2.常用時間函式

curdate(); #獲取當前的日期 年-月-日

now(); #獲取當前時間 年-月-日 時:分:秒 2020-09-15 11:25:33

to_days(now()); #就是從0年開始 到當前的天數

year(now()); #獲取當前的年份

month(now()); #獲取當前的月份

day(now()); #獲取當前的號數

3. grade 要不為null 要不是0-100的值

alter table sc

add check (grade like 『[null|0-100]』)

SQL時間日期處理

1.當前系統日期 時間 select getdate 2.dateadd 在向指定日期加上一段時間的基礎上,返回新的 datetime 值 例如 向日期加上2天 select dateadd day,2,2004 10 15 返回 2004 10 17 00 00 00.000 3.datediff...

SQL時間日期函式

getdate 函式 以datetime的預設格式返回系統當前的日期和時間 語法格式 getdate year month day 函式 返回date expression中的年份,月份,日期值 語法格式 year month day date expression datetime varchar...

Hive 時間日期處理總結

獲取當前時間截 select unix timestamp 結果 1539595903獲取當前時間1 select current timestamp 結果 2018 10 15 17 34 09.721獲取當前時間2 select from unixtime unix timestamp 結果 2...