473,407 Members | 2,629 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,407 software developers and data experts.

Time Question

In C# if I want to know the time in hours (fractional as well) between two
times how would I do that?

Current code is as follows:
DateTime startTime =
DateTime.Parse(e.Row.Cells["StartTime"].Value.ToString());

DateTime endTime = DateTime.Parse(e.Row.Cells["EndTime"].Value.ToString());

TimeSpan totalTime = endTime.TimeOfDay - startTime.TimeOfDay;

Decimal test = totalTime.Minutes / 60;

Sean
Nov 15 '05 #1
3 1097
Does this code work for you?
-mike
MVP

"Sean Fullerton" <se**@mypantsemonarch.net> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
In C# if I want to know the time in hours (fractional as well) between two
times how would I do that?

Current code is as follows:
DateTime startTime =
DateTime.Parse(e.Row.Cells["StartTime"].Value.ToString());

DateTime endTime = DateTime.Parse(e.Row.Cells["EndTime"].Value.ToString());
TimeSpan totalTime = endTime.TimeOfDay - startTime.TimeOfDay;

Decimal test = totalTime.Minutes / 60;

Sean

Nov 15 '05 #2
I think what you're looking for is the TimeSpan.TotalHours property.

HabibH.

"Sean Fullerton" <se**@mypantsemonarch.net> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
In C# if I want to know the time in hours (fractional as well) between two
times how would I do that?

Current code is as follows:
DateTime startTime =
DateTime.Parse(e.Row.Cells["StartTime"].Value.ToString());

DateTime endTime = DateTime.Parse(e.Row.Cells["EndTime"].Value.ToString());
TimeSpan totalTime = endTime.TimeOfDay - startTime.TimeOfDay;

Decimal test = totalTime.Minutes / 60;

Sean

Nov 15 '05 #3
Thanks, I found that right after I posted this. I appreciate the post!

Sean

"Habib Heydarian [MSFT]" <ha****@microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
I think what you're looking for is the TimeSpan.TotalHours property.

HabibH.

"Sean Fullerton" <se**@mypantsemonarch.net> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
In C# if I want to know the time in hours (fractional as well) between two times how would I do that?

Current code is as follows:
DateTime startTime =
DateTime.Parse(e.Row.Cells["StartTime"].Value.ToString());

DateTime endTime =

DateTime.Parse(e.Row.Cells["EndTime"].Value.ToString());

TimeSpan totalTime = endTime.TimeOfDay - startTime.TimeOfDay;

Decimal test = totalTime.Minutes / 60;

Sean


Nov 15 '05 #4

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

Similar topics

7
by: Valiz | last post by:
Hi, I am updating system time with IRIG time source which sends irregular pulses as shown below 11000011111100111111111111111111....(1-IRIG present and 0-IRIG not present) I need to update...
0
by: SimonC | last post by:
I'm looking to do something similar to a feature found on Ticketmaster.com, where you select your seats at a venue, and then you have two minutes in which to take or leave them. QUESTION 1a....
2
by: Steve Miller | last post by:
hello... i am a 'user' of access, meaning, i import excel files, join, and merge....that's about the extent of my expertise with ms-access. my boss wants me to create an access application that...
8
by: MLH | last post by:
I have database apps that depend on accurate time settings on the system clock. Fancy that, huh? Well, am trying to sync w/ the gvt's nist time server. From a CMD window in Win XP, I type the...
14
by: George | last post by:
In Time.h there is a structure defined for time settings. I'm building an embedded system that has a Real Time Clock but it's not PC compatible. My question is: I don't some elements of the...
1
by: Rob T | last post by:
This is just a general question....trying to collect some ideas on how to approach this issue: I have a web app that has users across the country. Since they login, I can make their profiles...
15
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
9
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As...
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
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
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
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
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...

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.