select CONVERT(nvarchar(50), '2018-10-10 10:13:32.000', 126) select convert(nvarchar(MAX), '2018-10-10 10:13:32.999',126) -- 考试记录(员工答题答案,项目ID,题目ID,员工ID,原答案,要顯示測驗日期時間、答案(只有英文字母都 還有同事姓名及分行 IF EXISTS (select * from sysobjects where id = object_id(N'[dbo].VipExamAnswerRecord') and OBJECTPROPERTY(id, N'IsUserTable') = 1) DROP TABLE VipExamAnswerRecord GO create table VipExamAnswerRecord ( AnswerRecordID INT IDENTITY(1,1) PRIMARY KEY, AnswerExamProjectId int not null, --项目ID AnswerBranchStaffID int not null, --员工ID AnswerExamQuestionsID int not null, --问题ID AnswerAskAnswer NVARCHAR(100) NULL, -- 考試者選的答案 AnswerQuestionsAnswer NVARCHAR(100) NOT NULL, -- 原题正确答案 AnswerIsOk BIT DEFAULT(0), -- 1正确,0不正确 AnswerRecordDate datetime2 default(getdate()) --添加时间 ) go -- datetime 2007-05-08 12:35:29.123 -- datetime2 2007-05-08 12:35:29. 1234567 declare @d1 datetime ,@d2 datetime2 set @d1=getdate() set @d2=getdate() select @d1,@d2 go select getdate(); go SELECT CONVERT(VARCHAR(28), GETDATE(), 126) IF EXISTS (SELECT * FROM sysobjects WHERE [name] = 'proc_Select_VipExamAnswerStaffDateSearch') DROP PROCEDURE proc_Select_VipExamAnswerStaffDateSearch GO CREATE PROCEDURE proc_Select_VipExamAnswerStaffDateSearch ( @AnswerBranchStaffID int, @AnswerExamProjectId int, @statDatetime datetime, -- 秒后小数只有3位 datetime2 秒后小数有7位,根据数据库的设定类型,在程序中也要考虑其一致,否则有查询上就有误差 Geovin Du 涂聚文提示 @endDatetime datetime -- 秒后小数只有3位 ) as declare @where nvarchar(500),@sql nvarchar(800) set @sql='select [BranchStaffName],[BranchStaffNO],[BranchStaffCode],BranchName,[ExamQuestionsTitle],ExamProjectTitle,[AnswerAskAnswer],[AnswerQuestionsAnswer],[AnswerIsOk],[AnswerRecordDate] from View_VipExamAnswerRecordHK where [AnswerRecordDate]>='''+CONVERT(nvarchar(50),@statDatetime,126)+''' and [AnswerRecordDate]<='''+CONVERT(nvarchar(50),@endDatetime,126)+'''' set @where='' set @where=@where+' and AnswerBranchStaffID='+cast(@AnswerBranchStaffID as varchar)+' and AnswerExamProjectId='+cast(@AnswerExamProjectId as varchar) set @sql=@sql+@where+' order by AnswerRecordDate desc' print(@sql) exec(@sql) go exec proc_Select_VipExamAnswerStaffDateSearch 2631,1,'2018-10-10 10:13:32.000','2018-10-10 10:21:43.999' go select CONVERT(nvarchar(50), '2018-10-10 10:13:32.000', 126) select convert(nvarchar(MAX), '2018-10-10 10:13:32.999',126)
Convert.ToDateTime(Eval("ExamRecordEndTime")).ToString("yyyy-MM-dd HH:mm:ss.fff