1.查詢當(dāng)前年、月、周相關(guān)時(shí)間1.1.查詢當(dāng)前年份SELECT TO_CHAR(SYSDATE,'YYYY') AS YEAR FROM DUAL--查詢當(dāng)前年份 SELECT TO_CHAR(SYSDATE,'YYY') AS YEAR FROM DUAL--查詢當(dāng)前年份后兩位 SELECT TO_CHAR(SYSDATE,'YY') AS YEAR FROM DUAL--查詢當(dāng)前年份最后兩位 SELECT TO_CHAR(SYSDATE,'Y') AS YEAR FROM DUAL--查詢當(dāng)前年份最后一位 1.2.查詢當(dāng)前年份第幾天SELECT TO_CHAR(SYSDATE,'DDD') AS DAYS FROM DUAL 1.3.查詢當(dāng)前月份第幾天SELECT TO_CHAR(SYSDATE,'DD') AS DAYS FROM DUAL 1.4.查詢當(dāng)前周的星期幾SELECT TO_CHAR(SYSDATE,'dy') AS WEEK FROM DUAL SELECT TO_CHAR(SYSDATE,'day') AS WEEK FROM DUAL 1.5.查詢當(dāng)前年的第幾天:SELECT TO_CHAR(SYSDATE,'DDD') AS DAYS FROM DUAL 2.查詢當(dāng)前第幾季度SELECT TO_CHAR(SYSDATE,'Q') AS JD FROM DUAL 3.查詢當(dāng)前在一年內(nèi)是第幾周SELECT TO_CHAR(SYSDATE,'IW') AS WEEKNUM FROM DUAL SELECT TO_CHAR(SYSDATE,'WW') AS WEEKNUM FROM DUAL SELECT TO_CHAR(SYSDATE,'W') AS WEEKNUM FROM DUAL 4.查詢當(dāng)前某年某月有多少天SELECT TO_CHAR(last_day(to_date('2019/02/01','YYYY/MM/DD')),'DD') AS MONTH_DAYS_NUMBER FROM DUAL 5.查詢當(dāng)前的日期格式SELECT TO_CHAR(SYSDATE,'YYYY/MM/DD') AS MONTH FROM DUAL--獲取當(dāng)前日期的'YYYY/MM/DD'格式:2020/01/02 SELECT TO_CHAR(SYSDATE,'YYYYMMDD') AS MONTH FROM DUAL--獲取當(dāng)前日期的'YYYYMMDD'格式:20200102 SELECT TO_CHAR(SYSDATE,'YYYYMMDD HH:MI:SS') AS now FROM DUAL--獲取當(dāng)前時(shí)間,精確到秒的12小時(shí)制格式:20200102 03:18:25 SELECT TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS now FROM DUAL--獲取當(dāng)前時(shí)間,精確到秒24小時(shí)制的格式:20200102 15:18:13 SELECT TO_CHAR(SYSDATE,'YYYY/MM/DD HH24:MI:SS:PM:DY') AS now FROM DUAL--獲取當(dāng)前時(shí)間的格式,顯示上、下午和星期幾:2020/01/02 15:17:59:下午:星期四 6.查詢距離當(dāng)前時(shí)間一段時(shí)間間隔的時(shí)間,當(dāng)前時(shí)間之前用“-”當(dāng)前時(shí)間之后用“+”SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7' second,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間的7秒前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7' minute,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間的7分鐘前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'hour ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間的7小時(shí)前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'day ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間的7天前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'month ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間的7月前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - INTERVAL '7'year ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間的7年前時(shí)間 SELECT TO_CHAR(SYSDATE, 'YYYY/MM/DD HH24:MI:SS') AS NOW,TO_CHAR(SYSDATE - 8*INTERVAL '7'hour ,'YYYY/MM/DD HH24:MI:SS') AS PAST FROM DUAL --查詢當(dāng)前時(shí)間參數(shù)年、月、日、時(shí)、分、秒乘以一個(gè)數(shù)字倍數(shù)之前的時(shí)間
|
|
來(lái)自: 新進(jìn)小設(shè)計(jì) > 《待分類》