每天学习一点点 编程PDF电子书免费下载: http://www.shitanlife.com/code cast(starttime as date): 时间转日期类型 实例SQL: SELECT COUNT (ID) AS pvNum, COUNT (DISTINCT userid) AS userNum, cast(starttime as date) AS staDay FROM t_e_visit_record WHERE true AND starttime >= '2018-03
--查询当天: 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 * 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