--查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info where DateDiff(hh,datetime,getDate())<=24 --本月记录 SELECT * FROM 表 WHERE datediff(month,[dateadd],getdate())=0 --本周记录 SELECT * FROM 表 WHERE
--根据日期查询星期SELECT SYSDATETIME();select datepart(weekday,getdate()); SET DATEFIRST 1select '星期'+case when cast(datepart(dw,getdate()) as char(1))= 7 then '天' else cast(datepart(dw,getdate()) as char(1)) end select @@datefirst; datefirst 一般美国采用星期天作为一周的第
select GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName(month,GetDate()) as '月',DateName(day,GetDate()) as '日',DateName(dw,GetDate()) as '星期',DateName(week,GetDate()) as '周数',DateName(hour,GetDate()) as '时',DateName(minute,GetDate()) as '
因项目要求,需要把SQLSERVER一张客户表的数据同步到oracle库的一张客户表,但两张表有时间类型不一致,需要进行转换 如下: SELECT CUSTCODE,AgreementValidity_Start, convert(datetime,replace(replace(replace(AgreementValidity_End,'年', '-'),'月','-'),'日','')) FROM [APEXMIS].[dbo].[Customer] where CUSTCODE='SZX
SELECT DATE_FORMAT(releaseDate,"%Y年%m月") AS dates,COUNT(*) FROM t_diary GROUP BY DATE_FORMAT(releaseDate,"%Y年%m月") ORDER BY DATE_FORMAT(releaseDate,"%Y年%m月") DESC ;releaseDate 日期 t_diary表名 DATE_FORMAT();按照格式对某个日期操作ORDER BY 排序
今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0昨天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=17天内的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=730天内的所有数据:select * from 表名 where DateDiff(dd