473,545 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2460
* "John" <jo**@nospam.in fovis.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_Additio n(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******** *****@TK2MSFTNG P09.phx.gbl...
* "John" <jo**@nospam.in fovis.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_Additio n(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(CD ate(startdates( i)))
totalspan = totalspan.Add(s pan(i))
Next
span.Sort(span)
MessageBox.Show ("min = " & span(0).ToStrin g & vbCrLf & _
"max = " & span(2).ToStrin g & vbCrLf & _
"avarage = " & totalspan.FromS econds _
(totalspan.Tota lSeconds / 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.A dd(duration)

I would bind this single startDateTime to a StartDateContro l & a
StartTimeContro l 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(s tartTime.TimeOf Day).Add(durati on)

startDate = temp.Date
startTime = DateTime.MinVal ue.Add(temp.Tim eOfDay)

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.in fovis.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP10.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******** *****@TK2MSFTNG P09.phx.gbl...
* "John" <jo**@nospam.in fovis.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_Additio n(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
2472
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 to use a parent window that allows the user to launch the calculation in a seperate window, so that they could still click "stop" to write a value to...
5
4678
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 based on? How do I calculate the Date when I have Unix seconds? Will the calculation take into account leap years? Thanks! Tom
5
6507
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 time is 2:00PM. The Break times are 1) 9:30 AM to 9:45 AM 2) 11:00AM to 11:30 AM 3) 12:30PM to 12:45 PM
10
3354
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: ---------------------------------------------------------------------- SELECT DateFilter.Employee, DateFilter.TimeTypeIn, Sum(-) AS Expr1 FROM...
8
2317
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 great part (maybe 80% or more) of the processor time and I want that it is for both 50% when the office program is using the processor. Is this...
5
6227
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 user modifies any of the x, y and z values.
3
3324
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} I can get the time NOW, but I am having trouble understanding the format/content of the document.lastModified field. Any help would be much...
1
1381
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 tables; in which, in any particular day, when it reaches that time, the system will automatically do some calculation. Now, i need to debug the part of...
6
11442
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 at once.) I recorded a macro to get the code, which I tweaked minimally, and pasted into a clean spreadsheet to test it. It seems to work...
2
1460
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 but when the time goes over 12:00 AM it appears that it was totaled twice. Ex: 4:00 PM (Time In1), 12:00 AM (Time Out2)= 16:00 Here’s the calculation...
0
7490
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7935
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7449
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5351
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.