?
Solved

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

Posted on 2010-11-18
3
Medium Priority
?
742 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 19

Accepted Solution

by:
Bardobrave earned 1000 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 1000 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 perform CRUD operations on a MySql database.
Suggested Courses

752 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