473,320 Members | 1,904 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,320 software developers and data experts.

TimeSpan object question

I haven't worked with the TimeSpan object before. So bare with me if
this seems like a newb question. But if I wanted to know how many
days from the current date until 2/4/2008. I have written this much
code so far.

DateTime startDate = new DateTime("2008-02-04");
DateTime curDate = DateTime.Now();
TimeSpan ts = startDate.Subtract(curDate);

Now I get lost. I was expecting to find a Days property off of the
TimeSpan object. No such luck. Where am I going wrong?

Thanks,
Kelly Greer
ke*********@nospan.com
change nospam to yahoo
Jan 23 '08 #1
4 2755
Kelly,

The Days property should be accessible through the ts variable. It's
definitely there. What makes you think it is not?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kellygreer1" <ke*********@yahoo.comwrote in message
news:bd**********************************@d21g2000 prf.googlegroups.com...
>I haven't worked with the TimeSpan object before. So bare with me if
this seems like a newb question. But if I wanted to know how many
days from the current date until 2/4/2008. I have written this much
code so far.

DateTime startDate = new DateTime("2008-02-04");
DateTime curDate = DateTime.Now();
TimeSpan ts = startDate.Subtract(curDate);

Now I get lost. I was expecting to find a Days property off of the
TimeSpan object. No such luck. Where am I going wrong?

Thanks,
Kelly Greer
ke*********@nospan.com
change nospam to yahoo

Jan 23 '08 #2
Hi,

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP********************@msnews.microsoft.com.. .
kellygreer1 <ke*********@yahoo.comwrote:
>Now I get lost. I was expecting to find a Days property off of the
TimeSpan object. No such luck. Where am I going wrong?

I'm not sure - TimeSpan definitely does have a Days property, and
always has had. What happens when you try to use ts.Days?
I believe that the correct property is TimeSpan.TotalDays
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Jan 23 '08 #3
On Wed, 23 Jan 2008 10:32:29 -0800, Ignacio Machin ( .NET/ C# MVP )
<machin TA <"laceupsolutions.com>"wrote:
>I'm not sure - TimeSpan definitely does have a Days property, and
always has had. What happens when you try to use ts.Days?

I believe that the correct property is TimeSpan.TotalDays
It depends on what the OP wants. If they just want the integral days
portion of the TimeSpan, Days is correct.
Jan 23 '08 #4
On Jan 23, 1:41 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Wed, 23 Jan 2008 10:32:29 -0800, Ignacio Machin ( .NET/ C# MVP )

<machin TA <"laceupsolutions.com>"wrote:
I'm not sure - TimeSpan definitely does have a Days property, and
always has had. What happens when you try to use ts.Days?
I believe that the correct property is TimeSpan.TotalDays

It depends on what the OP wants. If they just want the integral days
portion of the TimeSpan, Days is correct.
What I ended up doing was taking A ticks minus B ticks ... and then
dividing by the TimeSpan.TicksPerDay.
I'll fix this up tomorrow.

Wait. I just figured it out. Guess I was struck stupid today. I was
looking at the static side of TimeSpan and not an instance of
TimeSpan. Subtract 10 cool points. lol

Thanks guys,
Kelly
Jan 24 '08 #5

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

Similar topics

1
by: Doug | last post by:
Is it possible there is a bug with the System.TimeSpan object in .NET? I am using it to track times and am seeing an unusual situation. From what I understand, there are 1000 milliseconds in a...
2
by: Justin Grieves | last post by:
Hello all, I've been trying to determine the difference in minutes between two DateTime objects (startTime and endTime) in C# using the TimeSpan object (ts). I am populating the two DateTime...
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
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...
4
by: Peter Proost | last post by:
Hi group, it's been a long time since the last time I've been here but I have a question. I'm working with timespan.parse for calculating a duration, I have to add strings which are in the...
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: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.