How to schedule for this time format

Posted by Jayakumars under C# on 6/2/2017 | Points: 10 | Views : 1394 | Status : [Member] [MVP] | Replies : 1
Hi
I need Divide the time into slots in c#

I need created List object for StartTime, EndTime and SlotDuration,interval

If StartTime=9:00AM,

EndTime=5:00PM,

SlotDuration=10minutes

interval = 30 min

then I want to display the list object dynamically as

Morning:

9:00AM-9:10AM

9:40AM-9:50AM

10:20AM-10:30AM..........etc...

AfterNoon:

12:00PM-12:10PM

12:40PM-12:50PM................

like that

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Qyam on: 6/9/2017 [Member] Starter | Points: 25

Up
0
Down
Please follow the below steps to resolve your issue
1. create a below class containing 2 variables
Class A
{
datetime sTime;---will hold start time
Datetime eTime;--will hold end time
}

2. Declare below variables.
--considering below input for explanation
StartTime=9:00AM; --should be datetime
EndTime=5:00PM;--should be datetime
SlotDuration=10minutes;--int
interval = 30 min;--int

3. Loop through till end time
while (StartTime<=EndTime)
{
A objA=new A()--create instance of class created in step1
A.sTime=starttime;
a.eTime=Datetime.add(starttime+slotDuration);--add start time and slotDuration to get endtime
--Add object into list
list.add(a);
starttime=dattime.add(starttime+intervaltime)
}

4. while displaying merge like startime + '-'+endtime;

Hope it will resolve your issue.


Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response