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'.
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?
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'). - public ArrayList BetweenDates(string startDate, string endDate)
-
{
-
DateTime sdt = DateTime.ParseExact(startDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
-
DateTime edt = DateTime.ParseExact(endDate, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
-
ArrayList dates = new ArrayList();
-
do
-
{
-
-
if (Days.Contains(sdt.DayOfWeek.ToString()))
-
{
-
dates.Add(sdt.Date.ToString("yyyy-MM-dd"));
-
}
-
sdt = sdt.AddDays(1);
-
} while (sdt.CompareTo(edt) != 1);
-
return dates;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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
|
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...
| |
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).
...
|
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...
|
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.
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |