将SQL Server日期时间转换为较短的日期格式 [英] Convert a SQL Server datetime to a shorter date format

查看:359
本文介绍了将SQL Server日期时间转换为较短的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server中有一个 datetime 列,该列为我提供了这样的数据,例如 2010/10/27下午12:57:49 ,我想查询此列,但只让SQL Server返回日月和年-例如。 2010 10 27 或类似的东西。

I have a datetime column in SQL Server that gives me data like this 10/27/2010 12:57:49 pm and I want to query this column but just have SQL Server return the day month and year - eg. 2010 10 27 or something like that.

我应该研究什么功能?

What are the functions I should be researching?

我应该尝试转换为其他日期数据类型吗?还是直接将其转换为字符串?

Should I be trying to convert to another date data type? Or simply convert it to a string?

推荐答案

看看转换。第三个参数是您要转换为的日期时间样式。

Have a look at CONVERT. The 3rd parameter is the date time style you want to convert to.

例如

SELECT CONVERT(VARCHAR(10), GETDATE(), 103) -- dd/MM/yyyy format

这篇关于将SQL Server日期时间转换为较短的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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