0
    using (DataAccessAdapter adapter = new DataAccessAdapter())
       {
         LinqMetaData meta = new LinqMetaData(adapter);
         var datas = (from x in meta.Table
           where x.DateCreated >= startDate && x.DateCreated <= endDate && x.ViaTo > 0 && !x.Cancelled
           group x by new { month = x.DateCreated.Value.Month } into g
           select new
           {
            MonthNr = g.Key,
            //MonthName = ?
            TotalMonthAmount = g.Sum(x => x.Amount)
            });
.....
       }

And startDate & endDate are valid Dates.

I only get the month number, how to get the month name for the DateCreated?

Florin M.
  • 2,159
  • 4
  • 39
  • 97
  • No, I have only DateCreated which is a DateTime type. – Florin M. Apr 08 '15 at 11:10
  • 1
    possible duplicate of [how to get complete month name from DateTime](http://stackoverflow.com/questions/6765441/how-to-get-complete-month-name-from-datetime) – BCdotWEB Apr 08 '15 at 11:10

3 Answers3

4

You can get the month name using this function:

CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(monthNumber);
Richard
  • 21,728
  • 13
  • 62
  • 101
0

new { month = x.DateCreated.Value.Month.ToString("MMM") }

Lali
  • 2,816
  • 4
  • 30
  • 47
0

I think you are asking about Month property. Check this:

using System;

class Program
{
    static void Main()
    {
        DateTime now = DateTime.Now;
        //
        // Write the month integer and then the three-letter month.
        //
        Console.WriteLine(now.Month); //outputs 5
        Console.WriteLine(now.ToString("MMM")); //outputs May
    }
}
Gardax
  • 370
  • 1
  • 14