473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Time calculation

Hi

I have a start date and a start time field. I also have a timespan value
which can be anything from 5 minutes (TimeSpan(0, 5, 0)) to 2 weeks
(TimeSpan(14, 0, 0, 0)). How can I get an end date and end time (separate
fields) by adding timespan to start date & start time?

Thanks

Regards
Nov 20 '05 #1
4 2446
* "John" <jo**@nospam.infovis.co.uk> scripsit:
I have a start date and a start time field. I also have a timespan value
which can be anything from 5 minutes (TimeSpan(0, 5, 0)) to 2 weeks
(TimeSpan(14, 0, 0, 0)). How can I get an end date and end time (separate
fields) by adding timespan to start date & start time?


\\\
Dim ts As TimeSpan = New TimeSpan(5, 0, 0, 0)
Dim dtm As Date = DateTime.Now
dtm = Date.op_Addition(dtm, ts)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Hi

In my case the date and time are separate fields like that of an outlook new
appointment. So e.g startdate="18/07/2004" and start time = "13.00". Now I
need to add various time spans and get enddate & endtime as separate fields.

Thanks

Regards

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eJ*************@TK2MSFTNGP09.phx.gbl...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
I have a start date and a start time field. I also have a timespan value
which can be anything from 5 minutes (TimeSpan(0, 5, 0)) to 2 weeks
(TimeSpan(14, 0, 0, 0)). How can I get an end date and end time (separate fields) by adding timespan to start date & start time?


\\\
Dim ts As TimeSpan = New TimeSpan(5, 0, 0, 0)
Dim dtm As Date = DateTime.Now
dtm = Date.op_Addition(dtm, ts)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3
Hi John,

Does this question I once answered with a sample I made help you.

It is the calculation of an avarage time, however I think that all your
questions are in it.
\\\
Module main
Public Sub main()
Dim startdates() As String = _
{"01/01/2004 12:50", "02/01/2004 13:40", "02/01/2004 14:30"}
Dim enddates() As String = _
{"02/01/2004 18:40", "02/01/2004 13:57", "02/01/2004 19:50"}
Dim span(2) As TimeSpan
Dim totalspan As TimeSpan
For i As Integer = 0 To 2
span(i) = CDate(enddates(i)).Subtract(CDate(startdates(i)))
totalspan = totalspan.Add(span(i))
Next
span.Sort(span)
MessageBox.Show("min = " & span(0).ToString & vbCrLf & _
"max = " & span(2).ToString & vbCrLf & _
"avarage = " & totalspan.FromSeconds _
(totalspan.TotalSeconds / 3).ToString())
End Sub
End Module
///
Nov 20 '05 #4
John,
In addition to the other comments.

Hint: Outlook actually stores a single field, but displays it with two
controls!

I would have a startDateTime, add the TimeSpan, to get the new
startDateTime.

Dim startDateTime As DateTime = #7/1/2004 10:00:00 AM#

Dim duration As New TimeSpan(7, 5, 0, 0)

startDateTime = startDateTime.Add(duration)

I would bind this single startDateTime to a StartDateControl & a
StartTimeControl using the formatting previously given so each control only
displays its part, taking into consideration the "other half" when I put the
values back together...

Alternatively If I really needed both StartDate & StartTime fields, I would
combine the two fields, add the duration, then split the sum. However I
would look at using a single field first!

Dim startDate As DateTime = #7/1/2004#
Dim startTime As DateTime = #10:00:00 AM#
Dim duration As New TimeSpan(7, 5, 0, 0)

Dim temp As DateTime =
startDate.Add(startTime.TimeOfDay).Add(duration)

startDate = temp.Date
startTime = DateTime.MinValue.Add(temp.TimeOfDay)

Or I may use a combination of the above, for example my Domain Object may
have a single startDateTime field, but a StartDate & a StartTime property,
where the properties operate on their respective half of the startDateTime
field...

Hope this helps
Jay
"John" <jo**@nospam.infovis.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

In my case the date and time are separate fields like that of an outlook new appointment. So e.g startdate="18/07/2004" and start time = "13.00". Now I
need to add various time spans and get enddate & endtime as separate fields.
Thanks

Regards

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eJ*************@TK2MSFTNGP09.phx.gbl...
* "John" <jo**@nospam.infovis.co.uk> scripsit:
I have a start date and a start time field. I also have a timespan value which can be anything from 5 minutes (TimeSpan(0, 5, 0)) to 2 weeks
(TimeSpan(14, 0, 0, 0)). How can I get an end date and end time (separate fields) by adding timespan to start date & start time?


\\\
Dim ts As TimeSpan = New TimeSpan(5, 0, 0, 0)
Dim dtm As Date = DateTime.Now
dtm = Date.op_Addition(dtm, ts)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
5
by: Tom | last post by:
A field in a data set I want to import into Access is in Unix time (seconds from a certain time on a certain date). Does anyone know the precise date and the precise time on that date that Unix is...
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
10
by: Drum2001 | last post by:
I have designed a "Time Tracker Database"... Basically a Time Clock. I have report that calculates the number of regular hours worked per week. Currently I am running the following query: ...
8
by: andreas | last post by:
Hi, I have a calculation program in vb.net who is running for let us say for more than a hour. When I will do meanwhile something els in a office program I see that my calculation program takes a...
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
3
by: Gretsch | last post by:
Web, html, javascript, Hi, I need to calculate the time since this .htm file was last modified. {which I can then use in a calculation, rather than display, so days&decimals format would be OK}...
1
by: juliacjy | last post by:
Dear all, I'm needing an urgent help. I'm now maintaining a system which has a function of "Automatic Calculation". User is allowed to set of a time which then will be stored in one of my sql...
6
by: Lara1 | last post by:
I'm trying to get certain cells to show a hovering alert message when I click on them. (I don't want an error-message style box to pop up, because I'll eventually want it to show for lots of cells...
2
by: John Torres | last post by:
I created a form with “Time In1”, “Time Out1”, “Time In2”, “Time Out2”. I’m able to calculate the time correctly when it was during the day shifts from 7:00 AM (Time In1) 5:00 PM (Time Out1) = 10:00...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.