日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

impala 下的SQL时间函数

發(fā)布時間:2023/12/15 综合教程 29 生活家
生活随笔 收集整理的這篇文章主要介紹了 impala 下的SQL时间函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#把時間轉(zhuǎn)化成時間戳
select cast('1966-07-30' as timestamp);
select cast('1985-09-25 17:45:30.005' as timestamp);
select cast('08:30:00' as timestamp);

#取月份 無效月份為null
select hour('1970-01-01 15:30:00'),hour('1970-01-01 27:30:00');

#一周的第幾天
select dayofweek('2004-06-13');

#英文下的星期幾
select dayname('2004-06-13');

#兩個時間差
select datediff('2019-11-10','2019-11-20');

把時間戳轉(zhuǎn)換成秒數(shù)
select unix_timestamp(now())

把秒數(shù)轉(zhuǎn)成時間戳
select from_unixtime(cast(cast(1000.0 as decimal) as bigint));

把字符串轉(zhuǎn)換成時間戳
cast('2019-10-14 18:00:41' as timestamp)

#增加月份
select now(), add_months(now(), 2);
select now(), add_months(now(), -1);

#當前時間
select now(), current_timestamp();

#加6小時
select now() as right_now,date_add(now(), interval 6 hours) as in_6_hours;

#加三周
select now() as right_now,date_add(now(), interval 3 weeks) as in_3_weeks;

#加三個月
select date_add(cast('2016-01-31' as timestamp), interval 3 months) as 'april_31st';

#截取年份
select date_part('year',now()) as current_year;

#截取小時
select date_part('hour',now()) as hour_of_day;

#距現(xiàn)在之前的第七天
select now() as right_now,date_sub(now(), 7) as last_week;

#距現(xiàn)在之后第7天日期
select now() as right_now,date_sub(now(), -7) as last_week;

#前3周的那一天
select now() as right_now,date_sub(now(), interval 3 weeks) as 3_weeks_ago;

#6個小時前
select now() as right_now,date_sub(now(), interval 6 hours) as 6_hours_ago;

#上一個月
select date_sub(cast('2016-05-31' as timestamp), interval 1 months) as 'april_31st';

#相差的天數(shù)
select now() as right_now, datediff(now() + interval 5 days,now()) as in_5_years;

#取天數(shù)
select now(), day(now());

#一周的第一天,英文下的星期幾
select now() as right_now,dayofweek(now()) as todays_day_of_week,dayname(now()) as todays_day_name;

#截取年和月份
select now() as right_now,extract(year from now()) as this_year,extract(month from now()) as this_month;

#相差月份
select months_between('2015-02-28','2015-01-28');

#查詢當前時間的季初日期
select now() as right_now,trunc(now(), 'Q') as current_quarter;

#兩周之后的季初時間
select now() + interval 2 weeks as 2_weeks_from_now,trunc(now() + interval 2 weeks,'Q') as still_current_quarter;

#一年中的第幾周
select now() as right_now,weekofyear(now()) as this_week;

#之前的兩周時間點
select now() as right_now,weeks_sub(now(), 2) as week_before_last;

#截取年份
select now() as right_now,year(now()) as this_year;

#增加一年
select now() as right_now,years_add(now(), 1) as next_year;

總結(jié)

以上是生活随笔為你收集整理的impala 下的SQL时间函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。