如何从sql中的datetime列中仅提取时间 [英] How to extract only time from datetime column in sql
本文介绍了如何从sql中的datetime列中仅提取时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
选择PatientName,DATE_FORMAT(DOB,'%m /%d /%Y')作为DOB,年龄,DATE_FORMAT(CDate, '%m /%d /%Y')作为日期,CONVERT(VARCHAR(10),CTime,110)作为时间,遇到遇到的类型
// CONVERT (VARCHAR(10),CTime,110)作为时间错误部分
请帮助
Here is my code
select PatientName,DATE_FORMAT(DOB,'%m/%d/%Y') as DOB,Age,DATE_FORMAT(CDate,'%m/%d/%Y') as Date,CONVERT(VARCHAR(10),CTime,110) as Time,EncounterType from encounter
// CONVERT(VARCHAR(10),CTime,110) as Time "Error Section"
Please Help
推荐答案
select CONVERT(VARCHAR(10),CTime,108) as Time
收益率10:05:35
Yields 10:05:35
select FORMAT(CTime,'hh:mm:sstt') as Time
收益率10:05:35 AM >
注意:使用FORMAT()函数需要在SQL Server上安装.NET CLR
Yields 10:05:35AM
Note: Use of the FORMAT() function requires the .NET CLR to be installed on the SQL Server
本文介绍了可用于获取各种各样的部分。
http:// msdn .microsoft.com / zh-CN / library / ms187928.aspx [ ^ ]
This article shows the different numbers formats you can use to get the various parts.
http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]
这篇关于如何从sql中的datetime列中仅提取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文