Have you tried this?
DateTime.Now.AddHours(st)
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
You can use String.Format method, but it will return a string value of the time (not an actual time).
DateTime date = DateTime.Now;
string strTime = String.Format("{dd.MM.yyyy hh:mm}", date);
Do you explicitly wanna have a DateTime, and now a string?
If you only wanna add time (hours) you can simply use Add method in the time:
DateTime newTime = date.AddHours(2);
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
DateTime TestTime = DateTime.Parse(timeString1);
TestTime = TestTime + TimeSpan.Parse(timeString2);
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
Try this way
textBox1.text=cmd.ExecuteScalar().ToString();
DateTime Staff_Total_Hours = Convert.ToDateTime(textBox1.Text) + Convert.ToDateTime(txtTime.Text);
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
YOu cannot use + operator on DateTime. What exactly would you like to do?
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
Would you like to sum hours? I what format do you have hours?
In one textBox1 you have "10:00:00", that means "hour is 10am". What is in the 2nd textBox2?
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
DateTime Staff_Total_Hours = (Convert.ToDateTime(textBox1.Text)).ToTimeSpan().Add( (Convert.ToDateTime(txtTime.Text)).ToTimeSpan());
try ths
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
I have read your 1st post, and this is the colution for your troubles: :)
DateTime hour1 = Convert.ToDateTime(textBox1.Text);
DateTime hour2 = Convert.ToDateTime(textBox2.Text);
hour1 = hour1.AddHours(hour2.Hour).AddMinutes(hour2.Minute).AddSeconds(hour2.Second);
MessageBox.Show("Total date with hours is: " + hour1);
AS you can see, you have to convert both values to dateDate format. Then you have to add every sinlge date and/or time value to the date you want to "sum up". On this way you can add even years, months, miliseconds,..
bye, bye
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
Try this it will work IA :)
DateTime Time1=Convert.ToDateTime(txtTime.Text);
TimeSpan ts = new TimeSpan(Time1.Day, Time1.Hour, Time1.Minute, Time1.Second, Time1.Millisecond);
DateTime Staff_Total_Hours = DateTime.Parse(textBox1.Text).Add(ts);
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
DateTime Staff_Total_Hours = (Convert.ToDateTime(textBox1.Text)).ToTimeSpan().Add( (Convert.ToDateTime(txtTime.Text)).ToTimeSpan());
does not solve the problem
Dont you see my post on this 2nd page on the top? This is your solution.
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474