473,388 Members | 1,277 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,388 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 3544
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:
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.