[英]Date format in SQL Server 2008 R2
How to cast date for the following format in SQL Server 2008 R2: 如何在SQL Server 2008 R2中为以下格式转换日期:
Date: 日期:
'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)
This will convert it to a date and you can then compare it to `cast(getdate() as date). 这会将其转换为日期,然后可以将其与`cast(getdate()as date)比较。
The full list of formats for convert()
is in the documentation . convert()
格式的完整列表在文档中 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.