oracle常用的時間格式轉換 一

2021-08-31 14:08:45 字數 2526 閱讀 6571

1:取得當前日期是本月的第幾周

sql> select to_char(sysdate,'yyyymmdd w hh24:mi:ss') from dual;

to_char(sysdate,'yy

-------------------

20030327 4 18:16:09

sql> select to_char(sysdate,'w') from dual;

t -

4  2:取得當前日期是乙個星期中的第幾天,注意星期日是第一天

sql> select sysdate,to_char(sysdate,'d') from dual;

sysdate t

--------- -

27-mar-03 5 

類似:

select to_char(sysdate,'yyyy') from dual; --年

select to_char(sysdate,'q' from dual; --季

select to_char(sysdate,'mm') from dual; --月

select to_char(sysdate,'dd') from dual; --日

ddd 年中的第幾天

ww 年中的第幾個星期

w 該月中第幾個星期

d 週中的星期幾

hh 小時(12)

hh24 小時(24)

mi 分

ss 秒 

3:取當前日期是星期幾中文顯示:

sql> select to_char(sysdate,'day') from dual;

to_char(sysdate,'day')

----------------------

星期四 

4:如果乙個表在乙個date型別的字段上面建立了索引,如何使用

alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss' 

5: 得到當前的日期

select sysdate from dual;

6: 得到當天凌晨0點0分0秒的日期

select trunc(sysdate) from dual;

-- 得到這天的最後一秒

select trunc(sysdate) + 0.99999 from dual;

-- 得到小時的具體數值

select trunc(sysdate) + 1/24 from dual;

select trunc(sysdate) + 7/24 from dual; 

7.得到明天凌晨0點0分0秒的日期

select trunc(sysdate+1) from dual;

select trunc(sysdate)+1 from dual;

8: 本月一日的日期

select trunc(sysdate,'mm') from dual; 

9:得到下月一日的日期

select trunc(add_months(sysdate,1),'mm') from dual; 

10:返回當前月的最後一天?

select last_day(sysdate) from dual;

select last_day(trunc(sysdate)) from dual;

select trunc(last_day(sysdate)) from dual;

select trunc(add_months(sysdate,1),'mm') - 1 from dual; 

11: 得到一年的每一天

select trunc(sysdate,'yyyy')+ rn -1 date0

from

(select rownum rn from all_objects

where rownum<366);

12:今天是今年的第n天

select to_char(sysdate,'ddd') from dual; 

13:如何在給現有的日期加上2年

select add_months(sysdate,24) from dual; 

14:判斷某一日子所在年分是否為潤年

select decode(to_char(last_day(trunc(sysdate,'y')+31),'dd'),'29','閏年','平年') from dual; 

15:判斷兩年後是否為潤年

select decode(to_char(last_day(trunc(add_months(sysdate,24),'y')+31),

'dd'),'29','閏年','平年') from dual;

16:得到日期的季度

select ceil(to_number(to_char(sysdate,'mm'))/3) from dual;

select to_char(sysdate, 'q') from dual; 

python之常用的時間格式轉換

記得匯入需要的包例如 import datetime import time1.utc時間轉化為當地時間 cst時間 def utc2local utc date now stamp time.time local time datetime.datetime.fromtimestamp now s...

oracle中常用的日期格式轉換

格式化字串日期 select to date 20160912 yyyy mm dd from dual 以當前日期為基準,下乙個某天,1代表週日,2代表周一,以此類推 select next day to date 20160912 yyyy mm dd 3 from dual 計算n天之後或之前...

時間格式轉換 時間戳的轉換

1 thu mar 07 2019 12 00 00 gmt 0800 中國標準時間 轉換為 2019 03 07 12 00 00 const d new date thu mar 07 2019 12 00 00 gmt 0800 中國標準時間 const resdate d.getfullye...