473,398 Members | 2,188 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,398 software developers and data experts.

Timespan values - not negative?

coverDate = DateTime.Parse(objQuote.GetValue("coverStartDate") );
daysDiff = System.DateTime.Now.Subtract(coverDate);

I'm using this code trying to calculate the day difference between two
dates. However, daysDiff.days always returns a positive integer,
irrespective of whether the day is in the future or the past. How can I
get it to tell me whether the days difference is negative or positive?
(EG, yesterday compared to today should return -1)

Thanks,

Chris

Mar 27 '06 #1
1 10935

Chris Ashley wrote:
coverDate = DateTime.Parse(objQuote.GetValue("coverStartDate") );
daysDiff = System.DateTime.Now.Subtract(coverDate);

I'm using this code trying to calculate the day difference between two
dates. However, daysDiff.days always returns a positive integer,
irrespective of whether the day is in the future or the past.


Really? When I try

DateTime dt, dt2;

dt = DateTime.Now;
dt2 = dt.AddDays(1);

Console.WriteLine(dt.Subtract(dt2).Days);
Console.WriteLine(dt2.Subtract(dt).Days);

I get

-1
1

as I would expect.

--
Larry Lard
Replies to group please

Mar 27 '06 #2

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

Similar topics

1
by: pete | last post by:
I need to take many TimeSpan values and find their average. I know you can Add the many values together, but how do you then divide that result by the count of values that you had? Once I have...
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...
3
by: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
1
by: Rosanne | last post by:
I'm sure there's an easy solution to this that I am just not thinkin of. I am trying to get the total minutes between 2 times. It work fine except when the ending time crosses over midnight. For...
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 =...
11
by: parez | last post by:
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...
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...
4
by: Pachalo | last post by:
Morning... Am working on a simple billing system and a looking for a code that can help calculate the difference in time between sessions..(am using VB.Net ) This is what is happening: l...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...
0
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,...

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.