判斷首先要識別,要會轉換: 系統時間:from_unixtime(unix_timestamp() ,"yyyy-MM-dd HH:mm:ss") as ins_date 固定日期轉換成時間戳 select unix_timestamp("2016-08-16","yyyy-MM-dd") --1471276800 select unix_timestamp("20160816","yyyyMMdd") --1471276800 select unix_timestamp("2016-08-16T10:02:41Z", "yyyy-MM-dd"T"HH:mm:ss"Z"") --1471312961 時間戳轉換程固定日期 select from_unixtime(1471276800,"yyyy-MM-dd") --2016-08-16 select from_unixtime(1471276800,"yyyyMMdd") --20160816 select from_unixtime(1471312961) -- 2016-08-16 10:02:41 select from_unixtime( unix_timestamp("20160816","yyyyMMdd"),"yyyy-MM-dd") --2016-08-16 select date_format("2016-08-16","yyyyMMdd") --20160816 返回日期時間欄位中的日期部分 select to_date("2016-08-16 10:03:01") --2016-08-16 返回日期中的年 select year("2016-08-16 10:03:01") --2016 返回日期中的月 select month("2016-08-16 10:03:01") --8 返回日期中的日 select day("2016-08-16 10:03:01") --16 返回日期中的時 select hour("2016-08-16 10:03:01") --10 返回日期中的分 select minute("2016-08-16 10:03:01") --3 返回日期中的秒 select second("2016-08-16 10:03:01") --1 返回日期在當前的週數 select weekofyear("2016-08-16 10:03:01") --33 返回結束日期減去開始日期的天數 select datediff("2016-08-16","2016-08-11") 返回開始日期startdate增加days天后的日期 select date_add("2016-08-16",10) 返回開始日期startdate減少days天后的日期 select date_sub("2016-08-16",10) 返回當月的第一天 select trunc("2016-08-16","MM") --2016-08-01 select trunc("2016-08-16","YEAR") --2016-01-01
判斷首先要識別,要會轉換: 系統時間:from_unixtime(unix_timestamp() ,"yyyy-MM-dd HH:mm:ss") as ins_date 固定日期轉換成時間戳 select unix_timestamp("2016-08-16","yyyy-MM-dd") --1471276800 select unix_timestamp("20160816","yyyyMMdd") --1471276800 select unix_timestamp("2016-08-16T10:02:41Z", "yyyy-MM-dd"T"HH:mm:ss"Z"") --1471312961 時間戳轉換程固定日期 select from_unixtime(1471276800,"yyyy-MM-dd") --2016-08-16 select from_unixtime(1471276800,"yyyyMMdd") --20160816 select from_unixtime(1471312961) -- 2016-08-16 10:02:41 select from_unixtime( unix_timestamp("20160816","yyyyMMdd"),"yyyy-MM-dd") --2016-08-16 select date_format("2016-08-16","yyyyMMdd") --20160816 返回日期時間欄位中的日期部分 select to_date("2016-08-16 10:03:01") --2016-08-16 返回日期中的年 select year("2016-08-16 10:03:01") --2016 返回日期中的月 select month("2016-08-16 10:03:01") --8 返回日期中的日 select day("2016-08-16 10:03:01") --16 返回日期中的時 select hour("2016-08-16 10:03:01") --10 返回日期中的分 select minute("2016-08-16 10:03:01") --3 返回日期中的秒 select second("2016-08-16 10:03:01") --1 返回日期在當前的週數 select weekofyear("2016-08-16 10:03:01") --33 返回結束日期減去開始日期的天數 select datediff("2016-08-16","2016-08-11") 返回開始日期startdate增加days天后的日期 select date_add("2016-08-16",10) 返回開始日期startdate減少days天后的日期 select date_sub("2016-08-16",10) 返回當月的第一天 select trunc("2016-08-16","MM") --2016-08-01 select trunc("2016-08-16","YEAR") --2016-01-01