Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am trying to create dynamic time slots in c# based on the start time and end time with 20 minutes time interval. the start time and end time m getting from the user who enters in the textboxes. I want to store those time slots in the database (sql server). I have create time slots for static value. but when i am trying to fetch the value which is given by user which is string here is the problem how can i get the values from string to datetime.today.addhours???



Thank you
Posted
Updated 13-Sep-12 2:08am
v3
Comments
[no name] 13-Sep-12 7:58am    
Hi,

Convert.ToDateTime(strUserInput) didn't help?
Member 9413472 13-Sep-12 8:03am    
no actually I have the string value here below

string stime = dttimeslot.Rows[0]["day_start_time"].ToString();


i need that stime into
DateTime startTime = DateTime.Today.AddHours("what should be over here"(stime)).addminute;

the stime variable from the database and it has datetime datatype

how can i get those value from the database
Member 9413472 13-Sep-12 8:16am    
could somebody help me with the solution?
[no name] 13-Sep-12 8:26am    
Repost with no more information than the first time.
Member 9413472 13-Sep-12 8:55am    
like i have stime variable which has value from the database in the datetime format. i need only hours and minutes from that value so how can i get that with datetime.today.addhours()?

AddHours method gets a double (MSDN[^]) as argument, hence you have to convert your string to a double value (try the Double.Parse[^] method).
 
Share this answer
 
Hi,

From your explanation, I could come up with this answer. Let me know if this suits.

C#
DateTime startTime =Convert.ToDateTime(dttimeslot.Rows[0]["day_start_time"].ToString());
DateTime endTime=Convert.ToDateTime(dttimeslot.Rows[0]["day_end_time"].ToString());

while (startTime < endTime)
{
    startTime = startTime.AddMinutes(inc);
    //Your logic here
}


Does this help?
 
Share this answer
 
v3
Comments
Member 9413472 13-Sep-12 9:28am    
let me put my code

DataTable dttimeslot = (DataTable)cnt.GetRecord("Select day_start_time,day_end_time,facility_name,duration,provider_name from tblTimeSlots where facility_name='" + lsbcrlocation.Items[i].Text + "' and provider_name='" + lsbcrprovider.Items[j].Text + "'");


here i am calling the class getrecord to fetch the data from the database

now

DateTime stime =Convert.ToDateTime(dttimeslot.Rows[0]["day_start_time"].ToString());
DateTime etime =Convert.ToDateTime(dttimeslot.Rows[0]["day_end_time"].ToString());
string duration = dttimeslot.Rows[0]["duration"].ToString();

this is what i did as u suggest me

then
DateTime startTime = DateTime.Today.AddHours(stime.Hour);
DateTime endTime = DateTime.Today.AddHours(etime.Hour).AddMinutes(etime.Minute);



while (startTime < endTime)
{
timeList.Add(startTime.ToShortTimeString());
startTime = startTime.AddMinutes(inc);
lbltimeslots.Text += startTime.ToShortTimeString();
hrcls.upindel("insert into tblValidAppointmentTime(facility_name,provider_name,first_appointment_time) values('" + lsbcrlocation.Items[i].Text + "','" + lsbcrprovider.Items[j].Text + "','" + lbltimeslots.Text + "')");

//.ToShortTimeString();

}
but this is not going in to that loop and yeah its not taking starttime and endtime as format of time it is taking whole date and time while debugging i have check that

could you have solution with this?

thank you
[no name] 13-Sep-12 9:59am    
Hi,

Could you explain what you're trying to do? May be we could help you better.

Let us know of the algorithm, or steps you're trying to accomplish.
Member 9413472 13-Sep-12 10:09am    
i want to create timeslots of 15 minutes timeintervals based on the timing starttime and endtime which we have to fetch from the database. and then I want to store all the time slots in to another table of the database.

basically i have appointment page in that i want 15 minutes timeslots for appointment and i want to fetch those time slots from the database so based on the doctors shift timing which is stored in the database with starttime and endtime we have to generate time slots of lets say 15 minutes.

my concept is this and i have tried a lot but m not getting the things right i guess.

thank you for your help
[no name] 13-Sep-12 10:17am    
Based on your input, I've corrected the code snippet. Check and let me know.

See if it resolves.
Member 9413472 13-Sep-12 10:22am    
sorry but m new to this forum..but let me know where you made this changes?

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