Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a gridview on gridview i have a time calculation the thing is that when my first column is having a time 17:00 and when i select the 17:00 it will show me the 34:00 but i want the time is showing me the 10:00 how can i achieve this plz help

What I have tried:

var result = TimeSpan.Parse(ScheduleArrival.Text) + TimeSpan.Parse(LATE.SelectedValue + ":" + LATE2.SelectedValue + ":00");

EAT.Text = result.ToString();
Posted
Updated 30-Jul-18 20:09pm

Parsing looks a bit strange to me, and Id use DateTime parse instead since you want a pesific time registered here, and not a time gap:
var ts = DateTime.ParseExact(LATE.SelectedValue", "HHmm", CultureInfo.InvariantCulture).TimeOfDay;
 
Share this answer
 
Comments
Shahbaz435 31-Jul-18 2:10am    
Getting error in this code
var result = TimeSpan.Parse(ScheduleArrival.Text).Add (DateTime.ParseExact("LATE.SelectedValue", "HHmm", CultureInfo.InvariantCulture).TimeOfDay);

EAT.Text = result.ToString();

String was not recognized as a valid DateTime
Kenneth Haugland 31-Jul-18 2:24am    
What is this: LATE.SelectedValue? Can I see the actual value of this? and you should remove the "" as it should be a value, and you should call ToString() on it and make sure that it is a time format
Shahbaz435 31-Jul-18 2:36am    
Late should be take the hour "hhmm" this fiels should i remove
Try:
C#
EAT.Text = string.Format("{0}:{1}", result.Hours, result.Minutes);
 
Share this answer
 
Comments
Shahbaz435 31-Jul-18 2:13am    
Thanks done with thid code but if I'm attching the next day date so how can i implement the date also in this code can u plz help me for this
OriginalGriff 31-Jul-18 2:29am    
You need to show us exactly what is in your various text boxes and values, and explain in better detail exactly what you want to see as a final result - preferably with a couple of sample inputs and outputs!
Shahbaz435 31-Jul-18 2:36am    
should i show in the same textbox the date of next day
OriginalGriff 31-Jul-18 2:41am    
Stop trying to type as little as possible - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
The better the info you give us, the better the solution we can give you!
Shahbaz435 31-Jul-18 2:47am    
sir as you seen above my code is giving the next day time so afetr the plaaceholder it will be giving the next day time but i want the next day time as well as showing the next day time like 05:00 + 1 or 2 or 3 days like this

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