将varchar dd / mm / yyyy转换为dd / mm / yyyy datetime [英] Convert varchar dd/mm/yyyy to dd/mm/yyyy datetime
问题描述
我正在将 dd / mm / yyyy
格式的 varchar
列中的日期转换为日期时间 dd / mm / yyyy
格式,所以我可以在数据上运行日期范围查询。
I'm trying to convert a date in a varchar
column in the dd/mm/yyyy
format into the datetime dd/mm/yyyy
format, so then I can run date range queries on the data.
所以远程我有以下不工作
So far I have the following which is not working
CONVERT(varchar, CAST(date_started AS datetime), 103)
我也尝试过
convert(date_started as datetime, 103)
我需要确保输出为 dd / mm / yyyy
,因为我们在英国,而不是 mm / dd / yyyy
格式
I need to make sure the output is as dd/mm/yyyy
as we're in the UK and not the mm/dd/yyyy
format
推荐答案
我想你是这样的:
CONVERT(datetime, date_as_string, 103)
请注意, datetime
没有任何格式。你考虑它的演示。要以适当的格式获取 datetime
的数据,您可以使用
Notice, that datetime
hasn't any format. You think about its presentation. To get the data of datetime
in an appropriate format you can use
CONVERT(varchar, date_as_datetime, 103)
这篇关于将varchar dd / mm / yyyy转换为dd / mm / yyyy datetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!