HH:SQL Server中的MM格式

时间:2012-06-23 08:06:38

标签: sql-server

我正在使用存储过程并且我有一个列名称时间,我只想显示像HH:MM格式,程序工作正常,但唯一的问题是,目前花费的时间是hh:mm :ss格式。指导我如何花时间用HH:MM格式并尽可能纠正我的程序。 程序是这样的: -

CREATE procedure St_Proc_GetUserReportforCurrentDayTask              
@userID int              
as              
Begin              
    set NoCount on;              
    DECLARE @TODAY DATE                
    SET @TODAY = CONVERT(VARCHAR(10), GETDATE(), 111)              
    select CONVERT(VARCHAR,production.CalendarDate,101) + RIGHT (CONVERT(VARCHAR,production.CalendarDate , 100 ) ,7) as Date,               
    RegionAndProjectInfo.RegionProjectName as Region ,              
    County.CountyName as County,              
    WorkType.WorkTypeName as WorkType,              
    Task.TaskName as Task,  
    Production.VolumeProcessed as 'Volumes Processed',              
    Production.TimeSpent as 'Duration (HH:MM)'              
    from Production               
    inner join RegionAndProjectInfo              
    on              
    RegionAndProjectInfo.RegionProjectID=Production.RegionProjectID              
    inner join County              
    on               
    County.CountyID=Production.CountyID              
    inner join WorkType              
    on              
    WorkType.WorkTypeID=Production.WorkTypeID              
    inner join Task              
    on              
    Task.TaskID=Production.TaskID              
    where Production.UserID=@userID and CalendarDate >= @TODAY              
End 

2 个答案:

答案 0 :(得分:7)

试试这个

select SUBSTRING( convert(varchar, getdate(),108),1,5)

将getdate()替换为您的列名。

答案 1 :(得分:4)

我试过这个并且有效

declare @dt datetime
    set @dt = '07:30'
    select convert(varchar(5),@dt,108)