且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SQL存储过程中将长日期格式更改为短日期格式

更新时间:2023-02-12 22:16:07

日期是日期,没有别的!由于字段类型 [ ^ ]和几个设置 [ ^ ]日期格式可能不同。



要使用自定义格式显示日期,请检查:

日期和时间格式 [ ^ ]

CAST和CONVERT(Transact-SQL) [ ^ ]

FORMAT(Transact-SQL) [ ^ ]
Date is date and nothing else! Due to the type of field[^] and several settings[^] date format may differ.

To display date using custom format, please check this:
Date and Time Formats[^]
CAST and CONVERT (Transact-SQL)[^]
FORMAT (Transact-SQL)[^]


您似乎正在尝试在数据库服务器上格式化日期。我建议不要这样做。而是将日期值作为日期提取到客户端,并在那里处理格式。通过这种方式,您可以轻松确保使用正确的格式。



整体SQL用于数据获取和操作,并且它不适合格式化。其他语言和工具的目标是显示数据。
It seems that you're trying to format date on the database server. I would advice not to do this. Instead fetch the date value to the client side as date and handle formatting over there. This way you can easily ensure that correct format is used.

In overall SQL is meant for data fetching and manipulation and it's a poor candidate for formatting. Other languages and tools are targeted for displaying data.