SQL Server 2008 R2 中的日期格式 [英] Date format in SQL Server 2008 R2
本文介绍了SQL Server 2008 R2 中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 SQL Server 2008 R2 中为以下格式转换日期:
How to cast date for the following format in SQL Server 2008 R2:
日期:
'29-01-2008 AM 12:00:00'
我有上面的日期来检查表格的当前日期.
I have above date to check with the present date of the table.
如何只检查上述格式的日期?
How can I check only date from the above format?
推荐答案
如果你只想要日期,那么做:
If you want only the date, then do:
select convert(date, left('29-01-2008 AM 12:00:00', 10), 105)
这会将其转换为日期,然后您可以将其与 `cast(getdate() as date) 进行比较.
This will convert it to a date and you can then compare it to `cast(getdate() as date).
convert()
的完整格式列表位于文档.
The full list of formats for convert()
is in the documentation.
这篇关于SQL Server 2008 R2 中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文