473,372 Members | 892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Add all dates between startdate and enddate to arraylist

How do you take 2 dates (a startdate and an enddate), and then add all
the dates between them to an ArrayList?

This is as far as I have got so far, I'm not sure what to do next :

DateTime dtmStartDate = Convert.ToDateTime(dr["TaskStartDate"]);
DateTime dtmEndDate =
Convert.ToDateTime(dr["TaskEndDate"]);

TimeSpan ts = dtmEndDate - dtmStartDate;

arrTaskDates.Add(dtmStartDate);

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
2 2392
"Mike P" <mi*******@gmail.comwrote:
How do you take 2 dates (a startdate and an enddate), and then add all the
dates between them to an ArrayList?
Perhaps with a loop.

for (DateTime dt = start; dt <= end; dt = dt.AddDays(1))
{
list.Add(dt);
}

Eq.
Jun 27 '08 #2
On Jun 5, 12:01 pm, Mike P <mike.p...@gmail.comwrote:
How do you take 2 dates (a startdate and an enddate), and then add all
the dates between them to an ArrayList?

This is as far as I have got so far, I'm not sure what to do next :

DateTime dtmStartDate = Convert.ToDateTime(dr["TaskStartDate"]);
DateTime dtmEndDate =
Convert.ToDateTime(dr["TaskEndDate"]);

TimeSpan ts = dtmEndDate - dtmStartDate;

arrTaskDates.Add(dtmStartDate);
If you look at my MiscUtil library (http://pobox.com/~skeet/csharp/
miscutil) you'll find a range class, and a way of iterating through
any particular range. Combined with extension methods, you could
write:

dtmStartDate.To(dtmEndDate).Step(1.Days()).ToList( );

(Note that it would give you a List<Trather than an ArrayList.)

I *think* the Step stuff uses Marc Gravell's generic operator code
which requires .NET 3.5 (in the version checked into MiscUtil
currently). What version of .NET are you using? If you're still on 1.1
(which is possible given your wish to use ArrayList) you'll need to
write a loop such as:

for (DateTime date = dtmStartDate; date <= dtmEndDate; date =
date.AddDays(1))
{
list.add(date);
}

Jon
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be...
2
by: Mike N. | last post by:
I am currently using a function to validate a form on the client side (see code below). At the end of the function, I would like it to also compare a startDate against an endDate to ensure that the...
3
by: Lea | last post by:
Having a problem with a query within a table for appointment schedules. In this table tblMeetingInfo are two fields, StartDate and EndDate. The date information is entered into each of these...
2
by: Child | last post by:
I am trying to insert some data into a table and keep gettting the error: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. Its me testing the database so...
9
by: laurenq uantrell | last post by:
I've gotten sort of fed up with dealing with regional date settings on the client side and am considering the following scheme - just wondering if anyone has a negative view of it or not: ...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
1
by: coolnav | last post by:
Hi all, I am new to XML and XSLT. I am Creating an XML which has Date Value. My aim is to 1st sort all the xml data with respect to date. And then later i need to filter the date according...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a start and end date in my application. If a user does not know their dates yet, I want them, they will be null in the DB and I want them to be blank in the application. So, I'm trying to...
0
by: stavo23 | last post by:
I am using SQL Server 2000, and I want to write a stored procedure that returns certain values either between 2 dates (start and end) or the user enters a particular string. Its grafts a bit , but...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.