Solved

c# get list of months between two DateTimes, formatted as YYYYmm

Posted on 2010-11-18
3
672 Views
Last Modified: 2013-12-14
Hi

Can somebody show me a smart way to get a list of months between two DateTime values and format the results such as:

200811
200812
200901
200902
200903

Thanks

0
Comment
Question by:zattz
3 Comments
 
LVL 19

Accepted Solution

by:
Bardobrave earned 250 total points
ID: 34163898
You can use a loop from one date to another, increasing in each step first date on a month.

As you're working with date objects you can directly response it's year and month.
0
 
LVL 18

Assisted Solution

by:lludden
lludden earned 250 total points
ID: 34163933
System.DateTime StartDate = 1/1/2005 12:00:00 AM;
System.DateTime EndDate = 1/1/2009 12:00:00 AM;

while (StartDate < EndDate) {
	FileSystem.WriteLine(Strings.Format(StartDate, "yyyyMM"));
	StartDate = DateAndTime.DateAdd(DateInterval.Month, 1, StartDate);
}

Open in new window

0
 

Author Comment

by:zattz
ID: 34164290
Thanks.
I didnt realise you could loop through dates!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now