當前時間函式
(1)current_date
select current_date() from t1 limit 1 ;select unix_timestamp() from t1 limit 1;
(2)current_timestamp
select current_timestamp() from t1 limit 1 ;
(3)current_time
select current_time() from t1 limit 1 ;
(4)unix_timestamp
select unix_timestamp() from t1 limit 1;
2. 格式化時間字串
(1)unix_timestamp() , to_unix_timestamp()
unix_timestamp() 函式除了可以返回當前時間戳 ,另外加上引數(「yyyy'-'mm'-'dd' 'hh':'mm':'ss')也可返回指定日期時間戳 這時用法和 to_unix_timestamp() 一致 如:
(2)from_unixtime() 傳入int型別,預設返回 'yyyy'-'mm'-'dd' 'hh':'mm':'ss' 型別日期。select unix_timestamp('2019-07-11 15:20:00') from t1 limit 1;
select to_unix_timestamp("2019-07-11",'yyyy-mm-dd') from t1 limit 1;
也可以在後面加乙個字串引數,指定返回格式如 'yyyy/mm/dd hh'
select from_unixtime(1562829600) from t1 limit 1;
mysql中日期加減和hive中日期加減區別
先來看看mysql中日期的加減 mysql 為日期增加乙個時間間隔 date add now now函式為獲取當前時間 select date add now interval 1 day 加1天 select date add now interval 1 hour 加1小時 select dat...
sql中日期操作
1.看到乙個帖子,裡面日期操作函式挺多,方法技巧也挺好,學習了。declare s date select s 2012 01 01 定義開始日期 select cast datepart yy,dateadd dd,number,s as varchar 4 年 cast datepart mm,...
MySQL中日期問題
這是一種方法 select date format date sub current date interval 1 month y m 01 00 00 00 as prev month first,date format last day date sub current date interv...