Hi all,
I have a TimeSpan which i get my subtracing a date from a date.
TimeSpan ts (Dim ts As TimeSpan)
ts = parsedDate.Subtract(DateTime.Now)
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 4701
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.com
"parez" <ps*****@gmail.comwrote in message
news:11**********************@n15g2000prd.googlegr oups.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.Subtract(DateTime.Now)
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.Globalization.CultureInfo ci =
System.Globalization.CultureInfo.CurrentCulture;
DateTime parsedDate = DateTime.ParseExact(dt, expectF, ci,
System.Globalization.DateTimeStyles.None);
ts = parsedDate.Subtract(DateTime.Now);
Console.WriteLine("Total HOurs" + ts.TotalHours);
Console.WriteLine("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.Subtract(DateTime.Now)
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.com> 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.Subtract(DateTime.Now)
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.TotalHours 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.TotalHours 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...@nnowslpianmk.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
On Jun 13, 4:32 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Wed, 13 Jun 2007 13:24:02 -0700, parez <psaw...@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.TotalHours 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.
That is why I said "i will read the documentation properly next
time before posting."
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.
And no,it is not available in Konkani.
Paresh
"parez" <ps*****@gmail.comwrote in message
news:11********************@j4g2000prf.googlegroup s.com...
>
And no,it is not available in Konkani.
Hehe, maybe Microsoft should use that as a threat to their coders:
- If you screw up one more time, we'll give you the task of translating the
MSDN library to Konkani!
Paresh
Happy Coding
- Michael S 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...
|
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 =...
|
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...
|
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...
|
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...
|
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:
...
|
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,...
|
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...
|
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: 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: 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: 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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |