在Sql Server中从时间戳中删除秒 [英] Remove second from timestamp in Sql Server

查看:102
本文介绍了在Sql Server中从时间戳中删除秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从日历扩展程序存储日期时间并将其存储在数据库中.日期时间的格式为Format ="dddd,MMMM dd,yyyy".然后,我在网格视图中将此日期时间与其他字段一起显示,并将此字段命名为"CalendarDate".当前,网格中的CalendarDate显示为"6/29/2012 10:42:35 AM".

我希望日历日期将显示如下所示的日期:-"2012年6月29日上午10:42".仅几秒钟将被删除.请告诉我我该怎么做.

我现在正在使用的存储过程是这样的:-

I m storing datetime from a calendar extendar and storing it in the database.The Format of the datetime is Format="dddd, MMMM dd, yyyy". Then i m displaying this Datetime with other field in a grid view and naming this field as ''CalendarDate''. Currently the CalendarDate in the grid is displaying like "6/29/2012 10:42:35 AM".

I want that the Calendar date will display Date like this:-"6/29/2012 10:42 AM". Only seconds will be removed.Please advise me that how i do this.

The Stored Procedure which i m using now is like this:-

Create procedure St_Proc_GetUserReportforCurrentDayTask @userID int as
Begin
set NoCount on;
DECLARE @TODAY DATE
SET @TODAY = CONVERT(VARCHAR(10), GETDATE(), 111)
select Production.CalendarDate 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

推荐答案

您好,

请通过以下链接进行操作:
http://hamidseta.blogspot.in/2011/06/datetime-format-in- gridview.html [ ^ ]
http://www.aspdotnet-suresh.com/2011/05/how-to-set-date-format-in-gridview.html [
Hello,

PLease go through below link:
http://hamidseta.blogspot.in/2011/06/datetime-format-in-gridview.html[^]
http://www.aspdotnet-suresh.com/2011/05/how-to-set-date-format-in-gridview.html[^]

For you requirement, it will be like below:
<asp:boundfield datafield="Date" dataformatstring="{0:g}" headertext="CalendarDate" readonly="True" > </asp:boundfield><br />



从SQL Server的角度来看,在获取日期的同时尝试下面的查询:



From SQL Server, point of view, try below query while fetching the date:

SELECT CONVERT(VARCHAR,GETDATE(),101) + RIGHT (CONVERT(VARCHAR,GETDATE() , 100 ) ,7)


结果将如下所示:
MM/dd/yyyy HH:mm AM/PM.


Result will be like :
MM/dd/yyyy HH:mm AM/PM.


这篇关于在Sql Server中从时间戳中删除秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆