如何从 TSQL 日期时间字段中获取 YYYY-MM-DD 格式的日期? [英] How to get a date in YYYY-MM-DD format from a TSQL datetime field?

查看:22
本文介绍了如何从 TSQL 日期时间字段中获取 YYYY-MM-DD 格式的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以 YYYY-MM-DD 格式从 SQL Server 检索日期?我需要它与 SQL Server 2000 及更高版本一起使用.是否有一种简单的方法可以在 SQL Server 中执行此操作,或者在检索结果集后以编程方式进行转换会更容易吗?

How do I retrieve a date from SQL Server in YYYY-MM-DD format? I need this to work with SQL Server 2000 and up. Is there a simple way to perform this in SQL Server or would it be easier to convert it programmatically after I retrieve the result set?

我已阅读 Microsoft Technet 上的 CAST 和 CONVERT,但我想要的格式没有列出,更改日期格式也不是一个选项.

I've read the CAST and CONVERT on Microsoft Technet, but the format I want isn't listed and changing the date format isn't an option.

推荐答案

SELECT CONVERT(char(10), GetDate(),126)

限制您不想要的小时部分的 varchar 排版的大小.

Limiting the size of the varchar chops of the hour portion that you don't want.

这篇关于如何从 TSQL 日期时间字段中获取 YYYY-MM-DD 格式的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆