SQL 日期函数的使用

来源:互联网 发布:java长连接和短连接 编辑:程序博客网 时间:2024/05/22 03:03

--当月信息
select Sum(A_Time) as A_Time,user_Id from D_Time_Sheet
where datediff(month,sheet_Date,getdate())=0
group by user_Id

--获得某一个月上月的信息
declare @a datetime
set @a='2008-1-1'
select Sum(Duration) as Duration,user_Id from D_Time_Sheet
where datediff(month,sheet_Date,@a)=0
group by user_Id

--当日信息
select Sum(A_Time) as A_Time,user_Id from D_Time_Sheet
where datediff(d,sheet_Date,getdate())=0
group by user_Id

--去除时分秒的当前日期
print convert(varchar(10),getdate(),120)

--获取当前日期的日
print Day('2008-3-9')

--获取当月的信息
select Sum(Duration) as Duration,user_Id from D_Time_Sheet
where datediff(month,sheet_Date,'2008-1-1')=0
group by user_Id

UP_D_Time_Sheet_GetModel


USE PmsData
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'proc_Data' )
  DROP PROCEDURE  proc_Data
GO
/*---创建存储过程----*/
CREATE PROCEDURE proc_Data
  @writtenPass datetime
  AS
 select Sum(Duration) as Duration,user_Id from D_Time_Sheet
 where datediff(month,sheet_Date,'@writtenPass')=0
 group by user_Id
GO

EXEC proc_Data '2008-1-1'

 

create table users
(
use_id int primary,
user_time datetime
)
select * from dbo.DataTast where Birth_Data = getdate()
and SUBSTRING(convert(char(19),getdate(),120),12, 19)
between (SUBSTRING(convert(char(19),getdate(),120),12, 19)-15--就是这个取出的系统时间减15分钟--)
and SUBSTRING(convert(char(19),getdate(),120),12, 19)

select dateadd(minute,-5,getdate())

原创粉丝点击