2012-06-22 98 views
0

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

我希望日历日期显示日期如下: - “2012年6月29日上午10:42”。只有几秒钟将被删除。请告诉我,我是如何做到这一点。

存储过程现在用它IM是这样的: -

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 [email protected] and CalendarDate >= @TODAY    
    End 
+0

日期类型没有格式。只有在您将日期值转换为字符串时才使用特定的格式,反之亦然。 –

回答

0

做你自己的格式,通过采取过时的部分,将其转换为varchar,然后它们串在一起,例如:

select 
convert(varchar(2), (select DATEPART(month, GETDATE()))) 
+ '/' + 
convert(varchar(2), (select DATEPART(month, GETDATE()))) 
+ '/' + 
convert(varchar(4), (select DATEPART(year, GETDATE()))) 

作为备注:通常您的UI负责格式化日期。为什么不返回一个DateTime对象并让UI处理呢?

1

在Datagridview中为此数据字段使用dataformatstring="{0:g}"

<asp:BoundField HeaderText="CalendarDate" DataField="MyDateColumn" DataFormatString="{0:g}" >