OK
Thanks
The requirement is that I have a set number of hours and minutes eg; 01.30 and I need to multiply this by an integer
so 01:30 * 4 for example
Main Topics
Browse All TopicsThe code snippet below calculates the timespan between two periods
DateTime dtStart = DateTime.Parse(StartTime.T
DateTime dtEnd = DateTime.Parse(EndTime.Tex
TimeSpan ts = dtEnd.Subtract(dtStart);
/* calculate time with half hour */
string time = new DateTime(ts.Ticks).to.ToSt
however I need to amend the last line of code above so that I can use it in a calculation; The calculation is the time multiplied by a integer, for for example it could be 3 hours 30 minutes multiplied by 4
03:30 * 4
Currently it is formatted to a string; so how can I amend this so it can be used in calculation?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
OK thanks but I am not getting the correct calculation
Up to this point here is fine
DateTime dtStart = DateTime.Parse(txtClassSta
DateTime dtEnd = DateTime.Parse(txtClassEnd
TimeSpan ts = dtEnd.Subtract(dtStart);
Now say starttime was 0900am and end time 1130am - this gives 2 hours 30 minutes. Now I want to calculate this 2 hours 30 minutes by say 2; now this would be a total of 5 hours. This is what I need.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtStart, dtEnd, ts
dtStart = DateTime.Parse(StartTime.T
dtEnd = DateTime.Parse(EndTime.Tex
ts = DateDiff("n", dtStart, dtEnd) ' in case you need it in minutes
ts = ts * 2
ts = ts / 60
ts = Format(ts, "00.00")
ts = Replace(ts, ",", ":", 1, 1, CompareMethod.Text)
MsgBox(ts)
End Sub
Hi!
Public Function DateDiff(ByVal Interval As Microsoft.VisualBasic.Date
Namespace Microsoft.VisualBasic
Matti
HI Sorry
I cannot use that as I am using c# with asp.net
I have been told I must do it something like the previous comment like this
DateTime time = new DateTime(ts.Ticks);
string strFormatedTime = time.AddSeconds(ts.TotalSe
However it gives wrong result. If the time span is 2.5 hours and multiplied by 2 it gives result as 7.30 and not 5
That solution doesnt work....am trying to solve a similar problem and it doesnt work.
My problem is that when the date is after midnight teh timespan calculation is wrong.
Below is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim starttime As DateTime = DateTimePicker1.Value
Dim endtime As DateTime = DateTimePicker2.Value
Dim results As TimeSpan = starttime - endtime
TextBox1.Text = results.Duration.ToString
End Sub
Works but not for after midnight(stop time)
Business Accounts
Answer for Membership
by: MattiPosted on 2008-08-12 at 02:01:52ID: 22211097
Hi!
I'm not sure what you mean in calculations but lets try:
This is VB net now it's in hours but you can have the difference in minutes so you can go ti half hours
Two textboxes StartTime and EndTime and a button
Regards!
Matti
Select allOpen in new window