Hi all,
I have a TimeSpan which i get my subtracing a date from a date.
TimeSpan ts (Dim ts As TimeSpan)
ts = parsedDate.Subt ract(DateTime.N ow)
i get different values for Hours and TotalHours. In my case i was
geting -15 and -39.
The difference between two is 24 (i know it is obvious).
Also i can alsp tell that one use 00:00 and the other uses 23:59.
but why??
i using .net 1.1
thanks in advance 11 4716
parez,
You are going to have to give an actual code sample (it can't have Now
in it either, since that would not be a very definitive example, as the Now
property is always changing) as it's nearly impossible to tell based on what
you have shown.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"parez" <ps*****@gmail. comwrote in message
news:11******** **************@ n15g2000prd.goo glegroups.com.. .
Hi all,
I have a TimeSpan which i get my subtracing a date from a date.
TimeSpan ts (Dim ts As TimeSpan)
ts = parsedDate.Subt ract(DateTime.N ow)
i get different values for Hours and TotalHours. In my case i was
geting -15 and -39.
The difference between two is 24 (i know it is obvious).
Also i can alsp tell that one use 00:00 and the other uses 23:59.
but why??
i using .net 1.1
thanks in advance
On Wed, 13 Jun 2007 12:42:55 -0700, parez <ps*****@gmail. comwrote:
[...]
i get different values for Hours and TotalHours. In my case i was
geting -15 and -39.
The difference between two is 24 (i know it is obvious).
Also i can alsp tell that one use 00:00 and the other uses 23:59.
but why??
I agree with Nicholas that for best results, you should post a
concise-but-complete sample of code that reliably reproduces the
behavior. Then someone can answer the question in a very specific way.
That said, the simple answer is that Hours and TotalHours are two
completely different things. If you'll read the documentation for each,
you'll find that Hours is restricted to values between -23 and 23. In
other words, it's the "hours place" of a complete span of time. On the
other hand, TotalHours _is_ the complete span of time, represented as
hours.
It's sort of like the difference between saying that something takes 90
minutes to complete (where 90 is the total minutes), versus that it will
complete in 1 hour and 30 minutes (where 30 is the "minutes place" of the
time span).
Pete
string dt = "06/12/2007";
TimeSpan ts;
String[] expectF = new string[] { "%M/%d/yyyy", "%M/%d/
yyyy %H:mm" };
System.Globaliz ation.CultureIn fo ci =
System.Globaliz ation.CultureIn fo.CurrentCultu re;
DateTime parsedDate = DateTime.ParseE xact(dt, expectF, ci,
System.Globaliz ation.DateTimeS tyles.None);
ts = parsedDate.Subt ract(DateTime.N ow);
Console.WriteLi ne("Total HOurs" + ts.TotalHours);
Console.WriteLi ne("HOurs" + ts.Hours);
parez <ps*****@gmail. comwrote:
I have a TimeSpan which i get my subtracing a date from a date.
TimeSpan ts (Dim ts As TimeSpan)
ts = parsedDate.Subt ract(DateTime.N ow)
i get different values for Hours and TotalHours. In my case i was
geting -15 and -39.
The difference between two is 24 (i know it is obvious).
TotalHours gives the total hours within the timespan, so 3 days=72
hours.
Hours gives the hours modulo 24, i.e. in the range 0-23 for positive
timespans, or -23 to 0 for negative timespans.
So in this case your difference is 1 day and 15 hours, or a total of 39
hours.
Also i can alsp tell that one use 00:00 and the other uses 23:59.
Not at all sure what you mean by that.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
parez wrote:
Hi all,
I have a TimeSpan which i get my subtracing a date from a date.
TimeSpan ts (Dim ts As TimeSpan)
ts = parsedDate.Subt ract(DateTime.N ow)
i get different values for Hours and TotalHours. In my case i was
geting -15 and -39.
The difference between two is 24 (i know it is obvious).
Hours and TotalHours represent different things on the TimeSpan object.
Hours is the number of hours for the instance. TotalHours is the
total value of the timespan object expressed in hours. Since your
TotalHours is -39, that is greater than one day (24 hours in a day). In
that case, I would expect your Days value to be -1 and your hours value
to be -15. That, when converted to hours should match your integer part
of your total hours - (-1*24) + (-15) = -39.
Also i can alsp tell that one use 00:00 and the other uses 23:59.
To be more precise the other uses 23:59:59.999999 . While there are 24
hours in a day, once you pass 23:59:59.999999 you start a new day.
--
Tom Porterfield
Thanks for the reply.
I think i get it now. i will read the documentation properly next
time before posting.
This is why i got confused.This is from MSDN.
TimeSpan.Hours Property
Gets the number of whole hours represented by this instance.
TimeSpan.TotalH ours Property
Gets the value of this instance expressed in whole and fractional
hours.
My only excuse is that english is my 3rd language. :-)
On Wed, 13 Jun 2007 13:13:24 -0700, parez <ps*****@gmail. comwrote:
[posted code]
And?
Nicholas already asked you to not use DateTime.Now, and there's nothing
about the code you posted that suggests what issue you're having.
Finally, what about the answer I already provided does not explain the
issue to you?
If you want a more useful answer, you need to give us more to go on.
Pete
On Wed, 13 Jun 2007 13:24:02 -0700, parez <ps*****@gmail. comwrote:
This is why i got confused.This is from MSDN.
TimeSpan.Hours Property
Gets the number of whole hours represented by this instance.
TimeSpan.TotalH ours Property
Gets the value of this instance expressed in whole and fractional
hours.
But in addition to that, it also says:
The hour component of the current TimeSpan structure.
The return value ranges from -23 through 23.
And:
A TimeSpan value can be represented as [-]d.hh:mm:ss.ff,
where the optional minus sign indicates a negative time
interval, the d component is days, hh is hours as measured
on a 24-hour clock, mm is minutes, ss is seconds, and ff
is fractions of a second. The value of the Hours property
is the hours component, hh
My only excuse is that english is my 3rd language. :-)
While I don't know what your native language is, the MSDN documentation is
available in a wide variety of translations. There's a good chance that
includes your native language.
Pete
Sorry about that and thanks for the reply.
My questions have been answered.
On Jun 13, 4:29 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Wed, 13 Jun 2007 13:13:24 -0700, parez <psaw...@gmail. comwrote:
[posted code]
And?
Nicholas already asked you to not use DateTime.Now, and there's nothing
about the code you posted that suggests what issue you're having.
Finally, what about the answer I already provided does not explain the
issue to you?
If you want a more useful answer, you need to give us more to go on.
Pete
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 defined for the Date datatype. On the other hand,
Dim Elapsed as DateTime = Now + Now
does not give a compile time error but it thinks you're trying to
|
by: Charles Law |
last post by:
If I display a TimeSpan I get something like
00:05:17.6217891
when what I would like to see is
00:05:18
Is there an easy way to get this output? Try as I might I just can't find
it.
|
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 = TimeSpan.Zero
End Function
Error :
= is not corret
|
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 will fall somewhere between a Start & End time
Further more, there will be Break & Lunch times between Start & End.
Example...
Start 08:00
Break start 10:30
|
by: RicercatoreSbadato |
last post by:
I'd like to print a TimeSpan variable in this way:
00:00:00 --hh:mm:ss
(whitout the milliseconds)
how can I do it?
| |
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 there were 2 TimeSpan choices in the Intellisense drop
|
by: David |
last post by:
Hi,
using .NET 1.1 C#
I am trying to determine page generation time. I have
TimeSpan RenderTime = DateTime.Now - PageTime; (pagetime was set up in
oninit, Rendertime is in the render
I am using RenderTime.Seconds and RenderTime.Milliseconds in my string. (In
the brackets is just RenderTime, so that you can see the correct value)
|
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:
***************************************************************************************************************
{
...........................
PrintTimeSpanProblem();
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);
PrintTimeSpanProblem();
|
by: Michael C |
last post by:
IS there a reason Timespan doesn't have an operator for divide? Being that
it's an amount of time I would have thought it should. Really it's just a
wrapper around a double variable?
Thanks,
Michael
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |