SQL 在 Access 中将字符串转换为日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1397232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert a string to a date in Access
提问by Margaret
I'm migrating data between tables in Access 2003. In the old table, the date was stored as a text field in the format YYYYMMDD.
我正在 Access 2003 中的表之间迁移数据。在旧表中,日期存储为格式为 YYYYMMDD 的文本字段。
I want to store the field as a datetime in the new table. I've tried using CDate()
in my SQL statement, but it just displays as #Error
in the results.
我想将该字段存储为新表中的日期时间。我试过CDate()
在我的 SQL 语句中使用,但它只是#Error
在结果中显示。
What am I doing wrong?
我究竟做错了什么?
回答by shahkalpesh
e.g. cdate(format("20091231", "####/##/##"))
例如 cdate(format("20091231", "####/##/##"))
So, in your case it will be
所以,在你的情况下,它将是
SELECT cdate(format(mystringFieldThatIsInYYYYMMDDFormat, "####/##/##"))
FROM myData