SQL Server中的Datepart函数 [英] Datepart function in SQL Server

查看:85
本文介绍了SQL Server中的Datepart函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想以"MM"格式显示日期时间的月份部分.
例如,7月为"07",而不是7.

请协助,紧急.

问候,
Micah.

Hi,

I would like to display the month part of a datetime in the format "MM"
e.g July as "07" rather than 7.

Kindly assist, urgent please.

Regards,
Micah.

推荐答案



您可以使用convert函数转换日期格式.
Hi,

You can use convert function to convert date format.
select convert(varchar, getdate(),111);


请参阅此链接.
[ ^ ]


Refer this link.
[^]


您可能正在使用某些语言(例如c#或VB)在前端显示日期.在那里,您可以根据需要格式化日期,因为在SQL Server中没有直接格式化日期部分的方法.要在sql server中执行此操作,您将必须使用自己的算法.

阿努拉格(Anurag)
You may be displaying the date on front-end using some language such as c# or VB. There you can format the date as per your requirement, as there is no direct way of formatting the datepart in SQL server. To do it in sql server you will have to use your own algorithm.

Anurag


这篇关于SQL Server中的Datepart函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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