如何获得特定日期 [英] how to get particular date

查看:89
本文介绍了如何获得特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期格式为2/1/2011 12:00:00 AM(database)我只想显示月份和年份,例如,在这种情况下,JAN 2011

my date is in format 2/1/2011 12:00:00 AM(database ) i want to diplay only month and year i.e in this case JAN 2011

推荐答案

您需要像这样格式化日期:

You''ll need to format the Date like this:

var formatted = DateTime.Now.ToString("MMM yyyy");


SELECT MONTH(MyDateField)+''''+ YEAR(MyDateField)AS ShowDate FROM .. .

会给你月份和年份.但这会以数字形式表示月份. 2月2日.我不知道T-SQL中是否有任何功能可以为您提供当月的名称.

但是您可以通过以下代码轻松实现:

假设您有一个DateTime变量myDate,其中包含日期,那么您只需执行以下操作:

字符串showMonth = myDate.ToString("MMM yyyy");

祝你好运!
SELECT MONTH(MyDateField) + '' '' + YEAR(MyDateField) AS ShowDate FROM ...

Will give you month and year. But it will give the month as a number, e.g. 2 for February. I don''t know if there''s any function in T-SQL that will give you the NAME of the month.

But you can easily do it in code:

Assuming that you have a DateTime variable, myDate, containing then date, you simply do:

string showMonth = myDate.ToString("MMM yyyy");

Good luck!


请参阅:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx [ ^ ].

—SA
See this:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

—SA


这篇关于如何获得特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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