473,396 Members | 1,891 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.

TimeSpan Problem

Why is it that:

DateTime start = DateTime.Parse("1:00 AM");
DateTime stop = DateTime.Parse("2:30 AM");
TimeSpan ts = stop - start;
Response.Write(ts.Minutes.ToString());

Produces 30, not 90? How do I return the exact number of minutes between 2
times?

Thanks a lot.
Nov 8 '07 #1
5 1605
Because the number of minutes on the resulting TimeSpan is 30. If you
want to get the total number of minutes, you need to access the TotalMinutes
property.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<msnews.microsoft.comwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
Why is it that:

DateTime start = DateTime.Parse("1:00 AM");
DateTime stop = DateTime.Parse("2:30 AM");
TimeSpan ts = stop - start;
Response.Write(ts.Minutes.ToString());

Produces 30, not 90? How do I return the exact number of minutes between
2 times?

Thanks a lot.


Nov 8 '07 #2
What you need is ts.TotalMinutes

Nov 8 '07 #3
msnews.microsoft.com wrote:
Why is it that:

DateTime start = DateTime.Parse("1:00 AM");
DateTime stop = DateTime.Parse("2:30 AM");
TimeSpan ts = stop - start;
Response.Write(ts.Minutes.ToString());

Produces 30, not 90? How do I return the exact number of minutes between 2
times?
Because the Minutes property of the TimeSpan struct represents the
minutes in the hour, not the total number of minutes. Just use the
TotalMinutes property.

Chris.
Nov 8 '07 #4
Hi,

Take a look at TotalMinutes

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<msnews.microsoft.comwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
Why is it that:

DateTime start = DateTime.Parse("1:00 AM");
DateTime stop = DateTime.Parse("2:30 AM");
TimeSpan ts = stop - start;
Response.Write(ts.Minutes.ToString());

Produces 30, not 90? How do I return the exact number of minutes between
2 times?

Thanks a lot.


Nov 8 '07 #5
Perfect. Didn't even notice TotalMinutes. Thanks a lot.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:eN**************@TK2MSFTNGP04.phx.gbl...
Because the number of minutes on the resulting TimeSpan is 30. If you
want to get the total number of minutes, you need to access the
TotalMinutes property.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<msnews.microsoft.comwrote in message
news:uY**************@TK2MSFTNGP02.phx.gbl...
>Why is it that:

DateTime start = DateTime.Parse("1:00 AM");
DateTime stop = DateTime.Parse("2:30 AM");
TimeSpan ts = stop - start;
Response.Write(ts.Minutes.ToString());

Produces 30, not 90? How do I return the exact number of minutes between
2 times?

Thanks a lot.



Nov 8 '07 #6

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

Similar topics

5
by: Dirk Reske | last post by:
hey, when I do: TimeSpan ts = TimeSpan.FromTicks(System.Enviroment.TickCount); ts.ToString(); I get something like this: 00:00:00.2381474 but I want to see, how many hours,...
2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
2
by: ucasesoftware | last post by:
i translate a C# funtion to VB.NET and i have this : Shared Function isAllDay(ByVal ap As Appointment) As Boolean Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap.DateEnd.TimeOfDay =...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
2
by: Rob | last post by:
I was just getting started with TimeSpan and I get a error in my first line of code... I write... Dim ts as TimeSpan And Intellisense gives me an error "Type Expected" I did notice that...
5
by: prasanta.bhowmik | last post by:
Hello, I created a object of TimeSpan only with minute and expected the result in hours and minute, but its returning wrong result. My Code is : TimeSpan timeSpan = new TimeSpan(0,2400,0);...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
2
by: shapper | last post by:
Hello, I have the following: boxStat = new BoxStat { BoxCount = database.Boxes.Count(), SinceLastCreate = (DateTime.Now - database.Boxes.Max(b => b.CreatedAt)).Days ?? 0 };
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
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?
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
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...

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.