473,802 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Subtr act(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*********@nos pan.com
change nospam to yahoo
Jan 23 '08 #1
4 2777
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.co m

"kellygreer 1" <ke*********@ya hoo.comwrote in message
news:bd******** *************** ***********@d21 g2000prf.google groups.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.Subtr act(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*********@nos pan.com
change nospam to yahoo

Jan 23 '08 #2
Hi,

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** ************@ms news.microsoft. com...
kellygreer1 <ke*********@ya hoo.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.TotalD ays
--
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 <"laceupsolutio ns.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.TotalD ays
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...@nn owslpianmk.com>
wrote:
On Wed, 23 Jan 2008 10:32:29 -0800, Ignacio Machin ( .NET/ C# MVP )

<machin TA <"laceupsolutio ns.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.TotalD ays

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.TicksP erDay.
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
1842
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 second. I have a test I ran using the TimeSpan object which when I use TimeSpan.Milliseconds I got 658 but if I use TimeSpan.Seconds I get 5. If it took 658 milliseconds that should be less than 1 second right? 658 milliseconds should not...
2
7904
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 objects from the click of two buttons (start and stop) that I have placed on an ASP.NET webform. I have attempted to follow the many examples that are available on the web yet I'm finding that instead of returning the difference in minutes, my code is...
11
9731
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
2
19137
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
2
2949
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
13
2153
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
4
3305
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 following format 15:36:12 ==Hours, minutes, seconds but sometimes there is a string like 55:26:32 ==which is correct cause the production machine was busy for 55 hours, but the timespan.parse crashes on this value because it expects 2.7:26:32. I've...
5
5513
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); Console.WriteLine(timeSpan.Hours+':'+timeSpan.Minutes); Its Displaying me the result is 16:00, but expected result is 40:00.
5
2008
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();
0
9699
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, 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...
0
10538
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
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,...
0
9115
agi2029
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...
0
6838
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();...
0
5494
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.