简体   繁体   English

转换日期格式

[英]Convert Date Format

User updated in Excel as 01-03-2010 (as in DD-MM-YYYY ). 用户在Excel中更新为01-03-2010(与DD-MM-YYYY )。 How do I covert this into YYYYMMDD in SQL? 如何在SQL中将其转换为YYYYMMDD I have tried using FromDate=Format(Sheet1.Range("A3"),"yyyymmdd") and when I executed the SQL statement, it doesn't show any result. 我尝试使用FromDate=Format(Sheet1.Range("A3"),"yyyymmdd") ,当我执行SQL语句时,它没有显示任何结果。

If you are looking for dates on 20100301 then you usually need to filter like this 如果您要查找20100301上的日期则通常需要像这样进行过滤

WHERE MyDate >= '20100301' AND MyDate < '20100302'

The column MyDate is likely to have a time component so if you use equals it fails. MyDate列可能具有时间成分,因此,如果使用equals,它将失败。 Or you can strip the time off the column but this would cause the db engine to not use an index, so it's better to do a range query as per my example. 或者,您可以删除列中的时间,但这会导致db引擎不使用索引,因此最好按照我的示例进行范围查询。

BTW, yyyymmdd is the correct format . 顺便说一句, yyyymmdd是正确的格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM