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 GOcreate table VipExamAnswerRecord(AnswerRecordID INT IDENTITY(1,1) PRIMARY KEY,AnswerExamProjectId int not null, --项目IDAnswerBranchStaffID int not null, --员工IDAnswerExamQuestionsID int not null, --问题IDAnswerAskAnswer 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. 1234567declare @d1 datetime ,@d2 datetime2set @d1=getdate()set @d2=getdate()select @d1,@d2goselect getdate();goSELECT CONVERT(VARCHAR(28), GETDATE(), 126)IF EXISTS (SELECT * FROM sysobjects WHERE [name] = 'proc_Select_VipExamAnswerStaffDateSearch')DROP PROCEDURE proc_Select_VipExamAnswerStaffDateSearchGOCREATE 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)goexec proc_Select_VipExamAnswerStaffDateSearch 2631,1,'2018-10-10 10:13:32.000','2018-10-10 10:21:43.999'goselect 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