Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

sql-server - 如何从TSQL日期时间字段获取YYYY-MM-DD格式的日期?(How to get a date in YYYY-MM-DD format from a TSQL datetime field?)

How do I retrieve a date from SQL Server in YYYY-MM-DD format?

(如何以YYYY-MM-DD格式从SQL Server检索日期?)

I need this to work with SQL Server 2000 and up.

(我需要这个与SQL Server 2000及更高版本一起工作。)

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?

(有没有一种简单的方法在SQL Server中执行此操作,还是在检索结果集后以编程方式更容易地进行转换?)

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.

(我已阅读Microsoft Technet上的CAST和CONVERT ,但未列出我想要的格式,并且不能更改日期格式。)

  ask by Kinze translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
SELECT CONVERT(char(10), GetDate(),126)

限制您不想要的小时部分的varchar印章的大小。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...