473,396 Members | 1,760 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,396 software developers and data experts.

Working out the number of hours between two dates?

I want to work out how many hours there is between a start time and a finish
time.

For example

Start Time: 10:00 am
Finish Time: 11:00 am

Is 1 hour?

How can this be achieved using VB.NET?

--
Wayne Taylor
www.kryptos.co.uk/blog
Jul 21 '05 #1
3 3547
pm
DateTime dt1 = new DateTime(2004,01,01,12,0,0,0);
DateTime dt2 = new DateTime(2004,01,01,14,0,0,0);
TimeSpan ts = dt2-dt1;
Console.WriteLine( dt1.ToString() );
Console.WriteLine( dt2.ToString() );
Console.WriteLine( ts.ToString() ) ;

"Wayne Taylor" wrote:
I want to work out how many hours there is between a start time and a finish
time.

For example

Start Time: 10:00 am
Finish Time: 11:00 am

Is 1 hour?

How can this be achieved using VB.NET?

--
Wayne Taylor
www.kryptos.co.uk/blog

Jul 21 '05 #2
Use the System.TimeSpan:
Dim start As DateTime = DateTime.Now;
Dim end As DateTime = start + New TimeSpan(1, 0, 0);
Dim span As TimeSpan = end - start
Console.WriteLine(span.Hours)
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Wayne Taylor" <wt*@online.parity-ict.com> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...
I want to work out how many hours there is between a start time and a
finish time.

For example

Start Time: 10:00 am
Finish Time: 11:00 am

Is 1 hour?

How can this be achieved using VB.NET?

--
Wayne Taylor
www.kryptos.co.uk/blog

Jul 21 '05 #3
And watch for C# semantics (eg ';')

:)

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:CI******************@news2.e.nsc.no...
Use the System.TimeSpan:
Dim start As DateTime = DateTime.Now;
Dim end As DateTime = start + New TimeSpan(1, 0, 0);
Dim span As TimeSpan = end - start
Console.WriteLine(span.Hours)
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Wayne Taylor" <wt*@online.parity-ict.com> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...
I want to work out how many hours there is between a start time and a
finish time.

For example

Start Time: 10:00 am
Finish Time: 11:00 am

Is 1 hour?

How can this be achieved using VB.NET?

--
Wayne Taylor
www.kryptos.co.uk/blog


Jul 21 '05 #4

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

Similar topics

1
by: Jesse O | last post by:
I have two date fields, start_date and end_date. I'd like to subtract the two dates, and come up with a number (the number of difference between the two dates). What function is there to do...
4
by: GRoll21 | last post by:
Hey this is my first time posting on of these. the program just gets the employee number, then it gets hours, how much they get paid, then figures total. for some reason its not liking my last...
3
by: adam.sherratt | last post by:
Ayup! I am currently working on a Capacity Planning project for my office, and i'm interested to hear your thoughts on the best way to approach something. here's the scenario; The...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
4
by: Totto | last post by:
Hi, Is ther a simple way to calculate number of hours in a date range. (dtFrom as date , dtTo as date) Had a look at timespan, but can's see that it's possible to add dates. Tnx Totto
3
by: Wayne Taylor | last post by:
I want to work out how many hours there is between a start time and a finish time. For example Start Time: 10:00 am Finish Time: 11:00 am Is 1 hour?
3
by: Jason Huang | last post by:
Hi, In our C# Windows Form application, we are using the SQL Server 2000 as the database server. The Database table MyTable has a field RegistrationDate which represents the Date a client comes...
4
by: jnice814 | last post by:
I have created a frmTimesheet form where auditors will enter their hours for audits that they've worked on. I know how to build a very basic, no-frills database, and what I'm trying to accomplish...
2
by: angi35 | last post by:
Hi, I'm working in Access 2000. I have a form with a series of date fields, showing the progress of a project from start to completion. There's a set of fields/controls for projected dates (when...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.