Q: Time and Date

G

Geoff Jones

Hi

I have question regarding times and dates in a datatable.

I have one table with one column having the date e.g.03/09/04, and another
column other the time 08:03:05. The other table has one column with the
date/time e.g. 09/06/04 13:05:03.

What is the easiest way for me to calculate the difference in time, in
seconds, between the rows of each table?

Thanks in advance

Geoff
 
H

Herfried K. Wagner [MVP]

* "Geoff Jones said:
I have question regarding times and dates in a datatable.

I have one table with one column having the date e.g.03/09/04, and another
column other the time 08:03:05. The other table has one column with the
date/time e.g. 09/06/04 13:05:03.

What is the easiest way for me to calculate the difference in time, in
seconds, between the rows of each table?

For data(base) related questions, give this group a try:

<URL:
Web interface:

<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framework.adonet>
 
G

Geoff Jones

I will certainly re-post but I thought this the best newsgroup because I'm
dealing with tables in datasets.

Geoff
 
C

Cor Ligthert

Hi Geoff,

And dates which are in VB special however it is such a not nice problem to
answer you have.

I do it simple and type it in here,
You have in my idea to set your values from your dataset to VB date fields.
When needed use Cdate(dr(0)) or something

Than you can use some of the date.add functions to add the time.

After that you need the timespan to calculate the difference what is very
easy with two dates.
http://msdn.microsoft.com/library/d.../cpref/html/frlrfsystemtimespanclasstopic.asp

What is strange with the date as with the timespan is that all are methods,
so not
date = date + x however
date = date.add(whatever)

I hope this gives some idea how to do it,

When after a while trying it yourself not, reply than I will see if I can
make a sample?

Cor
dealing with tables in datasets.

Geoff

Herfried K. Wagner said:
For data(base) related questions, give this group a try:

<URL:
Web interface:
<URL:http://msdn.microsoft.com/newsgroups/?dg=microsoft.public.dotnet.framew
 
J

Jay B. Harlow [MVP - Outlook]

Geoff,
In addition to the other comments.
What is the easiest way for me to calculate the difference in time, in
seconds, between the rows of each table?
Do you want to know the difference between row(1) and row(2) or the
difference between col(1) and col(2)?
Or did you want to know the difference between table(1).row(1) &
table(2).row(1)

And once you have this difference, what do you want to do with it?

You can use a simple For loop to see all the rows in a table.

Dim table As DataTable
For Each row As DataRow in table.Rows
Next

If you are matching rows in tables, is there a parent child relationship?
You can define a DataRelation & use DataRow.GetParentRow or
DataRow.GetChildRows to get the related rows...

If you wanted just wanted to know about Dates & Times, you can use the
various methods on both the DateTime & TimeSpan structures.

Something like:

' define the variables coming from your DataTable.
Dim theDate As DateTime = #3/9/2004#
Dim theTime As DateTime = #8:03:05 AM#
Dim theDateTime As DateTime = #9/6/2004 1:05:03 PM#

' theDate = theDate + theTime
Dim tsTime As TimeSpan = theTime.Subtract(DateTime.MinValue)
theDate = theDate.Add(tsTime)

' tsDiff = theDate - theDateTime
Dim tsDiff As TimeSpan = theDate.Subtract(theDateTime)

' Print the total seconds
Debug.WriteLine(tsDiff.TotalSeconds, "seconds")

Hope this helps
Jay
 
G

Geoff Jones

Ah., the code you sent was exactly what I was looking for. Many thanks

Geoff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top