如何仅从GetDate()获得时间 [英] How to get only Time from GetDate()
本文介绍了如何仅从GetDate()获得时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何仅从GetDate()获取时间.格式为hh:mm PM/AM.
最后,我的要求是获取介于10.00 AM到8.30 PM之间的随机时间.
How to get only Time from GetDate(). Format is hh:mm PM/AM.
Finally my requirement is to get Random Time between 10.00 AM to 8.30 PM.
推荐答案
您可以将日期转换为某个时间.例如:
you can cast the date to a time. For example:
select cast(getdate() as time)
使用
CONVERT( VARCHAR(8), Getdate(), 108)
查找CAST和CONVERT
Lookup CAST and CONVERT
您可以使用TimeOfDay属性获取特殊日期的时间:
You can use TimeOfDay property to get the time of a special date:
DateTime Date = new DateTime(Your datetime);
String Time = Date.TimeOfDay.ToString();
这篇关于如何仅从GetDate()获得时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文