Click here to Skip to main content
15,915,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

Here my problem is u want to find different month name with year ... how to get for ex

if i gave Nov-2015 to Jan-2016 mean i want to display
like

Nov-2015
Dec-2015
Jan-2016

how to get like this ... i get the datetime value from datetimepicker in windows applications.

Thanks
Posted

1 solution

C#
var start = new DateTime(2013, 1, 1);
var end = new DateTime(2013, 6, 22);

// set end-date to end of month
end = new DateTime(end.Year, end.Month, DateTime.DaysInMonth(end.Year, end.Month));

var diff = Enumerable.Range(0, Int32.MaxValue)
                     .Select(e => start.AddMonths(e))
                     .TakeWhile(e => e <= end)
                     .Select(e => e.ToString("MMMM"));



do you google?[^]
 
Share this answer
 
Comments
prasanna.raj 8-Jan-16 6:31am    
where i can declare e ... showing error like can't declare e
Andy Lanng 8-Jan-16 6:32am    
You will need to add the linq library reference
prasanna.raj 8-Jan-16 6:44am    
i added linq library like this
1)In a Visual Basic or C# project, click the Project menu, and then click Add Reference.

2)In the Add Reference dialog box, click the .NET tab, scroll to System.Core.dll, and then click it. ...
3)Add a using directive or Imports statement for System.Linq to your source code file or project.

even though i got same error and i added linq namespace also ... what can i do ..
Andy Lanng 8-Jan-16 6:52am    
oh! do you already have a variable named 'e'?

I tried it myself and it's fine with just using System; for the date types and using System.Linq; for the linq & lambda. If I remove the using System.Linq; then it complains about the Enumerable class before the the lambda

PS: By lambda, I mean the Func syntax: [param]=>[function] or e => e <= end
That says
"call the input parameter 'e'" (e=>)
"perform a boolean check 'e' is less than or equal to 'end'" (e <= end)
prasanna.raj 8-Jan-16 7:16am    
i already use linq ... sorry am not get you clearly ...how can i change this

var diff = Enumerable.Range(0, Int32.MaxValue)
.Select(e => start.AddMonths(e))
.TakeWhile(e => e <= end)
.Select(e => e.ToString("MMMM"));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900