暫時用到日期的相關操作

2021-06-18 07:27:23 字數 1606 閱讀 8917

oracle:

1.獲取當前日期當前周,周一的日期

select trunc(sysdate+1, 'yyyy') - to_char(trunc(sysdate+1, 'yyyy'), 'd') - 5 +

(select to_char(sysdate+1, 'ww') from dual) * 7 startweek

from dual;

2.獲取當前日期當前周,週日的日期

select trunc(sysdate+1, 'yyyy') - to_char(trunc(sysdate+1, 'yyyy'), 'd') + 1 +

(select to_char(sysdate+1, 'ww') from dual) * 7 as endweek

from dual;

3.oracle中日期的表示:

select to_char(sysdate,'cc ww w d ddd yyyy/mm/dd year month day') from dual

cc    為世紀

ww 為一年中的周

w      為乙個月中的周

d       為星期幾

ddd 為一年中的第幾天

year   為年 

month 為月

day      為星期幾

4.差今天是本月的第幾周

select to_char(sysdate,'ww')-to_char(trunc(sysdate,'mm'),'ww')+1 weekofmon from dual;

sqlserver 

1.獲取當前日期當前天的周一和週日日期

select 

convert(varchar(10),getdate()-(datepart(weekday,getdate())-2),120),

convert(varchar(10),getdate()+(8-datepart(weekday,getdate())),120)

select    datepart(hh,sendtime) 時間 ,count(1)  smo from tb_smslog (nolock)  a --  group by  convert(varchar(100), a.sendtime, 23)

where datediff(day,sendtime,getdate())=1 and smstype='wxbd' group by datepart(hh,sendtime) order by 時間

2.sqlserver 日期問題,查詢convert  和datepart這兩個函式。效果不錯哦

如下例:11月

where datepart(mm ,oa_monthplan.dopertime)='11'

select    datepart(hh,sendtime) 時間 ,count(1)  smo from tb_smslog (nolock)  a --  group by  convert(varchar(100), a.sendtime, 23)

where datediff(day,sendtime,getdate())=1 and smstype='wxbd' group by datepart(hh,sendtime) order by 時間

日期時間相關操作

當前日期時間的獲取 datetime datetime1 datetime.now 日期時間的運算 string str1 datetime1.addyears 1 tostring 加年份 string str1 datetime1.addmonths 1 tostring 加月份 string ...

Domino日期操作相關

1 將字串格式的日期轉為日期格式 texttotime 例 texttotime 1987 05 18 2 查詢日期 假如被搜尋文件中沒有日期域。用 created.searchstr searchstr webdoc.totime 0 3 公式中日期的比較 date today date adju...

javascript日期相關操作

時間戳轉時間格式 function getmydate str function getzf num return num 時間戳轉時間格式end 格式化日期 yyyy mm dd function formatdate strtime if day 9 return date.getfullyea...