sql獲取日期

2021-05-17 20:50:19 字數 1334 閱讀 8329

declare

@aa varchar(20)

set @aa= convert(varchar(100), getdate(), 23)

--//日

print @aa+' 0:00:00.000'

print @aa+' 23:59:59.999'

--//周

print convert(varchar(100), dateadd(wk, datediff(wk,0,getdate()), 0), 23)+' 0:00:00.000'

print convert(varchar(100), dateadd(wk, datediff(wk,0,getdate()), 6), 23)+' 23:59:59.999'

--//月

print convert(varchar(100), dateadd(m, datediff(m,0,getdate()), 0), 23)+' 0:00:00.000'

print convert(varchar(100), dateadd(m, datediff(m,0,getdate()), 30), 23)+' 23:59:59.999'

select distinct (userid),sum(score) as sumscore from ph where endtime between @aa+' 0:00:00.000' and @aa+' 23:59:59.999' group by userid order by sumscore desc

select distinct (userid),sum(score) as sumscore from ph where endtime between convert(varchar(100), dateadd(wk, datediff(wk,0,getdate()), 0), 23)+' 0:00:00.000' and convert(varchar(100), dateadd(wk, datediff(wk,0,getdate()), 6), 23)+' 23:59:59.999' group by userid order by sumscore desc

select distinct (userid),sum(score) as sumscore from ph where endtime between convert(varchar(100), dateadd(wk, datediff(wk,0,getdate()), 0), 23)+' 0:00:00.000' and convert(varchar(100), dateadd(wk, datediff(wk,0,getdate()), 6), 23)+' 23:59:59.999' group by userid order by sumscore desc

SQL當前日期獲取技巧

當前日期 select convert varchar 10 getdate 120 乙個月第一天的sql 指令碼 select dateadd mm,datediff mm,0,getdate 0 本週的星期一 select dateadd wk,datediff wk,0,getdate 0 一...

SQL當前日期獲取技巧

當前日期 select convert varchar 10 getdate 120 乙個月第一天的sql 指令碼 select dateadd mm,datediff mm,0,getdate 0 本週的星期一 select dateadd wk,datediff wk,0,getdate 0 一...

SQL中只獲取日期值

datatime型的字段make date,裡面的值是 2002 12 02 00 00 00.000 我用什麼函式,或者簡便的方法,可以取出像這樣的資料 2002 12 02 只取日期,月日要補零 要得到不同格式的日期和時間,你需要使用函式convert 例如,當下面的這個語句執行時,顯示的時間將...