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

Difference in seconds from two datetime objects

Ron
How can I find the difference in seconds of two DateTime objects. I have
looked at the Subtract method but this gives me back another DateTime
object.
Thanks,

Ron
Nov 18 '05 #1
1 9448
Ron wrote:
How can I find the difference in seconds of two DateTime objects. I have
looked at the Subtract method but this gives me back another DateTime
object.


Actually, DateTime.Subtract( TimeSpan) returns a DateTime object, but
DateTime.Subtract( DateTime) gives you a TimeSpan object. The
TotalSeconds property of this will give you what you want:

(datetime2.Subtract( datetime1)).TotalSeconds

or

(datetime2 - datetime1).TotalSeconds

Be careful not to mistakenly use the "Seconds" property of the TimeSpan
object, as this only gives you the seconds *component* of the TimeSpan,
which will always be in the range 0-59.

--
mikeb
Nov 18 '05 #2

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

Similar topics

8
by: Paulo Jan | last post by:
Hi all: I have here a table with the following schema: Table "todocinetv" Column | Type | Modifiers...
2
by: Paperback Writer | last post by:
How could I extract the difference bewteen times like this: 4:56:09am 4:59:10 The difference is: 00:03:01 How do I accomplish this ? Thanks in advance, Daniel
2
by: Randall Parker | last post by:
I know I could just get the year,month,day, etc of of each DateTime vars and calc the hours difference between them. I've done this before in other languages with a formula for handling leap years....
15
by: Snuyt | last post by:
Hello, I want the program to wait a few seconds between executing code. It should look something like this: public sub xx() ...code... wait(2) 'wait 2 seconds ...code...
5
by: prileep | last post by:
Hi, I want to find the the exact difference between two dates in seconds through MySQL query. Version: 4.1 Platform: Linux Source code: >select datediff('2007-01-09 10:24:46','2007-01-09...
5
by: Konstantinos Pachopoulos | last post by:
Hi, does any body now any such algorith? to find difference in days from YYYYMMDD to YYYYMMDD? Or just an algorithm, that converts YYYYMMDD to seconds since the epoch? Thanks
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
3
by: RN1 | last post by:
A Form has 2 TextBoxes where in users enter date & time. Example (in mm/dd/yyyy format): 09/20/2008 17:54 (1st TextBox) 09/29/2008 6:13 (2nd TextBox) How do I find out how much time (in...
7
by: 23rnj3mn32sdjqw | last post by:
Hi, It should be simple - but I am trying to find the difference between two datetimes as an integer in seconds. Using pywin32 build 212, python 2.5, Windows XP Pro, MySQL 5.0. import time...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
jinu1996
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...
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
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.