473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to find the dates between two dates

5 New Member
How can I get the dates between two dates depending on days?
For example, if I give the start date '10-05-2010' and end date '24-05-2010' and days are Mon, Wed, Fri , the result should be '10-05-2010', '12-05-2010', '14-05-2010', '17-05-2010', '19-05-2010', '21-05-2010', '24-05-2010'.
May 7 '10 #1
2 3386
tlhintoq
3,525 Recognized Expert Specialist
This looks very much like a school homework problem.

Have you made any effort to code this beforenasking for help?
May 7 '10 #2
khaing
5 New Member
It is not a school homework.
I try to write and I did it.
Here is the code.
The startDate and endDate comes in dd-MM-yyyy format and the 'Days' variable contains the days (eg.,'Monday Wednesday Friday').


Expand|Select|Wrap|Line Numbers
  1. public ArrayList BetweenDates(string startDate, string endDate)
  2.         {
  3.             DateTime sdt = DateTime.ParseExact(startDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
  4.             DateTime edt = DateTime.ParseExact(endDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
  5.             ArrayList dates = new ArrayList();           
  6.             do
  7.             {
  8.  
  9.                 if (Days.Contains(sdt.DayOfWeek.ToString()))
  10.                 {
  11.                     dates.Add(sdt.Date.ToString("yyyy-MM-dd"));                    
  12.                 }
  13.                 sdt = sdt.AddDays(1);
  14.             } while (sdt.CompareTo(edt) != 1);
  15.             return dates;
  16.         }
May 10 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: PW | last post by:
<rant> Sorry guys, but I just have to whinge. Dates in ASP are a total pain in the butt! I seem to get caught out so many times. I realise its my own fault, but going from the posts in this...
3
by: David | last post by:
I'm new to DB2 and I need to write a query that will allow me to find specific dates instead of me having a date range asked for, I want it to be calculated. I've done this in Access by coding...
2
by: Stewart Allen | last post by:
Hi There I have a function that does some calculations depending on the 2 date arguments passed into it: Function GetPeriods(dteStart As Date, dteEnd As Date) As Integer The function has 2...
3
by: Jerry | last post by:
How do I find the dates of the Sunday and Saturday of a week if I have the week number of a selected year? Thanks! Jerry
1
by: David Lozzi | last post by:
Howdy, Users can specify a date in a field labeled dtDate. This field in SQL is a smalldatetime. When I vew the raw data in the table, it displays 9/29/2008, and when a user doesn't specify a...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
13
newnewbie
by: newnewbie | last post by:
I have an Access database that I upload a data extract intoto daily. I want to create a query that will give me a list of dates that no data can be found for. E.g. there are no records created on the...
4
nirmalsingh
by: nirmalsingh | last post by:
hi all! i have to find the dates of sundays in a year. help me with sample code in C#. thanx in advance.
3
by: bobdydd | last post by:
Hi Everybody I am trying to be able to filter records by whether the date field which is called "RiskDate" in the recordset, is either: 1. Is Null 2. Not Null The parameter in the query...
2
by: sivasweety | last post by:
' TD1 to TD18 to get date values one by one. Dim Fd1, Fd2, Fd3, Fd4, Fd5, Fd6, Fd7, Fd8, Fd9, Fd10, Fd11, Fd12, Fd13, Fd14, Fd15, Fd16, Fd17, Fd18 As Date Dim TD1, TD2, TD3, TD4, TD5, TD6,...
0
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.