
正文
sqlserver当前月,sql 当月
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
SQLServer数据库取得当前时间
Year(getdate()) --当前年
Month(getdate()) --当前月
Day(getdate()) --当前日
Datediff(d,时间字段,getdate()) --得到离过生日还剩的天数
相关问答
Q1: sqlserver查询本月所有不在这个时间段的数据(如 整个四月份不在 7.30-8.30 12.30-13.30这个时间段)?
首先你得有字段记录时间,假设这个字段是datetime类型,名为[create_time];
然后,可以使用datepart函数来获取一个时间类型的年、月、日、时、分、秒的值;
最后,可以将hour:minute转换为一个带小数的类型来比较,例如numeric(4,2)。
select * from ...
where datepart(month,updtime)=4
and not datepart(hour,create_time) +convert(numeric(4,2),datepart(minute,create_time))/100 between 7.3 and 8.3
and not datepart(hour,create_time) +convert(numeric(4,2),datepart(minute,create_time))/100 between 12.3 and 12.3
Q2: 求助:SQLServer判断当前时间为当前月的最后
SQL code?
1
SELECT DATEADD(Day,-1,CONVERT(char(8),DATEADD(Month,1,@dt),120)+ '1 ')
Q3: SQLServer、Oracle获取当前年份的1月到当前月之间的所有月份
sqlserver:
select convert(varchar(7),dateadd(mm,-t.number,getdate()),120)
from
(select number from master..spt_values where type='P') t
where year(dateadd(mm,-t.number,getdate()))=year(getdate())
order by convert(varchar(7),dateadd(mm,-t.number,getdate()),120)
oracle:
select to_char(add_months(sysdate, -t.rn), 'yyyy-mm')
from dual a, (select rownum - 1 rn from dual connect by rownum = 12) t
where to_char(add_months(sysdate, -t.rn), 'yyyy') =
to_char(sysdate, 'yyyy')
order by to_char(add_months(sysdate, -t.rn), 'yyyy-mm')
Q4: sqlserver如何查询当月的第一个星期五?
说一下我的思路吧.首先查询出当前月的每一天进行排序,然后再对每一天进行星期几的查询,再定位第一个星期五,我们用的也是Oracle,语句应该也是大同小异.
select ndate(select trunc(sysdate,'mm')+level-1 as ndate from daul connect by level =31) t where to_char(ndate,'dy')='星期五' and rownum='1';







