Click here to Skip to main content
15,885,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to create appointment between two times and in each appointment there will be a gap or duration

example

from time: 10:00 am
to time: 2:00 pm

duration between time is 20 minutes
time will be shown like below

10:00 am 1st appointment
10:20 am 2nd appointment
10:40 am 3rd appointment
11:00 am 4th appointment
and so on..
Posted
Comments
Tomas Takac 29-Nov-14 3:08am    
What do you mean by "create appointment"? What is exactly the problem here? Are you asking how to add 20 minutes to a date/time?
itsathere 29-Nov-14 3:18am    
create appointment means 'arrangement for meeting'..
I have,
from time: 10:00 am
to time: 2:00 pm

duration between meeting is 20 minutes
then 1st meeting time will be at 10:00 am, 2nd will be at 10:20 and so on..

now problem is how to create the time duration gap of 20 minutes by for loop or while loop

1 solution

Try something like this:
C#
DateTime startTime = DateTime.Parse("10:00");
DateTime endTime = DateTime.Parse("14:00");
TimeSpan duration = new TimeSpan(0, 20, 0);
List<DateTime> appointments = new List<DateTime>();
while (startTime < endTime)
    {
    appointments.Add(startTime);
    startTime += duration;
    }
That builds a list of appointments at 20 minute intervals.
 
Share this answer
 
Comments
itsathere 29-Nov-14 3:20am    
i want to know with am-pm convertion not 14:00 that will be 2:00 pm
OriginalGriff 29-Nov-14 3:34am    
And did you try:

DateTime endTime = DateTime.Parse("2:00pm");

No?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900