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

Calculating number of seconds given two times

Hello,

I need to know how I can calculate the number of seconds between two
time stamps, e.g. if I have the following (using ToLongTimeString)

8:28:21 PM

and

9:02:33 PM

How can I find out the number of seconds elapsed between the two
times?

Thanks in advance.

Asad
Nov 18 '05 #1
2 1475
Hi Asad,

Look at the TimeSpan example:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
viewstate("starttime") = Now
Else
Dim tmspan As TimeSpan
tmspan = Date.Now.Subtract _
(CType(viewstate("starttime"), DateTime))
Label1.Text = tmspan.TotalSeconds.ToString
End If
End Sub
"Asad" <as*******@hotmail.com> wrote in message
news:fd**************************@posting.google.c om...
Hello,

I need to know how I can calculate the number of seconds between two
time stamps, e.g. if I have the following (using ToLongTimeString)

8:28:21 PM

and

9:02:33 PM

How can I find out the number of seconds elapsed between the two
times?

Thanks in advance.

Asad


Nov 18 '05 #2
Hello as*******@hotmail.com,

I'll presume that you have both times as DateTime objects. If not, you'll need to parse them and then call the Subtract method to get a TimeSpan object.

TimeSpan span = dt.Subtract(dt2);
int seconds = span.Seconds;
Hello,

I need to know how I can calculate the number of seconds between two
time stamps, e.g. if I have the following (using ToLongTimeString)

8:28:21 PM

and

9:02:33 PM

How can I find out the number of seconds elapsed between the two
times?

Thanks in advance.

Asad

--

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #3

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

Similar topics

6
by: Ralph Freshour | last post by:
What's a good way to calculate the number of days between two dates in the following format: 2003-07-15 2003-08-02 I've looked at the PHP date functions but I'm still a bit lost...
4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
36
by: Dag | last post by:
Is there a python module that includes functions for working with prime numbers? I mainly need A function that returns the Nth prime number and that returns how many prime numbers are less than N,...
3
by: Tim | last post by:
I need to get the number of seconds when subtracting two date/times. With the code I am using below I subtract the two date/times and end up with a total of days like "1.56". Then when I multiply...
4
by: cyril | last post by:
I saw that is a recurrent message but i couln't succed in founding the solution ... I'm developping under Linux Does anyone have a code snippet that permit to get in a simple long var the...
3
by: Miller | last post by:
Hi, Can someone tell me how to calculate MFLOPS for the following C# code (on a Pentium 4 2.0 Ghz)? for (i=0; i<n; i++) { for (j=0; j<n; j++) { for (k=0; k<n; k++)
6
by: bg_ie | last post by:
Hi, I wish to write a C program which obtains the system time and hence uses this time to print out its ntp equivalent. Am I right in saying that the following is correct for the seconds part...
9
by: clintonb | last post by:
I'm looking for a way to calculate the number of days between two dates using standard C++ functions. Would it be as simple as just using the difftime() function and then dividing that result by...
2
by: slinky | last post by:
Anyone know how to calculate the difference between two times displayed in two textboxes? I'm starting out with two textboxes: "txtCallTimeBegins" & "txtCallTimeEnds" this yielded: 6/7/2007...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.