473,480 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2396
"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
3900
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
8560
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
1617
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
1183
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
3273
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
2409
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
1407
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
1926
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
964
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
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5321
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4767
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.