如何从Linq的datetime列获取月份名称到SQL? [英] How to get Month Name from datetime column in Linq to SQL?

查看:72
本文介绍了如何从Linq的datetime列获取月份名称到SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表中有一个DateTime列.

在Linq to SQL查询中,我只需要该字段的Month部分

如何为此编写Linq查询?

谢谢

I have a DateTime column in my table.

In Linq to SQL query, I only need Month part of that field

how to write the Linq query for that?

Thanks

推荐答案



编写简单的选择查询,并使用DateTime结构.ToString("MMMM")方法获取月份名称.
我不知道您的表名和列名,所以我会写一些查询,您将需要调整表名和列名...
由于您没有提到语言,因此我将在C#中编写简单的代码片段...
Hi,

Write simple select query and use DateTime structure .ToString("MMMM") method to get month name.
I don''t know your table and column names so I''ll write some query and you will need to adjust your table and column names...
Since you didn''t mentioned language i''ll write simple code snippet in C#...
YourDataContext dc = new YourDataContext();
var monthNames = from d in 			
			(
				from row in dc.GetTable<YourTable>()
				select row.YourDateTimeColumn
			).ToList()
			select d.ToString("MMMM");
					 
monthNames.Dump();


这将为表中的每个记录返回月份名称.
如果要选择特定记录,请在查询中的位置使用.


This will return month names for every record in your table.
If you want to select specific record use where in your query.


hiiii,

hiiii,

object[] dt = { "13/01/2012","02/03/2012","04/03/2012","03/04/2012","06/05/2012" };
               List<string> result = (from d in dt select Convert.ToDateTime(d).ToString("MMMM")).ToList();


这篇关于如何从Linq的datetime列获取月份名称到SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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