SQL 如何在 Microsoft Access 查询中格式化日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23624859/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:52:17  来源:igfitidea点击:

How to format dates in microsoft access queries

sqlsql-serverms-access

提问by StackTrace

SELECT convert(varchar, getdate(), 101)

In Microsoft SQL Server, the above query returns the current date in the format

在 Microsoft SQL Server 中,上述查询以以下格式返回当前日期

mm/dd/yyyy - 05/01/2014

月/日/年 - 05/01/2014

What is its Microsoft Access query equivalent? I have tried CDate(MyDateValue)but this does not retain leading zeroes. In the example above, it returns

它的 Microsoft Access 查询等效项是什么?我试过,CDate(MyDateValue)但这不会保留前导零。在上面的例子中,它返回

5/1/2014

5/1/2014

but i need the leading zeroes.

但我需要前导零。

回答by vhadalgi

try using

尝试使用

format

format

select Format (#05/01/2014#, "mm/dd/yyyy") 

more info here

更多信息在这里

回答by Twin Tower

Try this select convert(date,getdate(),101)

试试这个 select convert(date,getdate(),101)