time of day to seconds

J

james

I am working with a very old database system (building an import/export routine) that stores the time in seconds. I have been
able to convert the seconds to correct time (thanks to a lot of help in this group).
But, I need to be able to write back the time of day to the db in seconds.
Example:
01:00:00 PM should be 46800 seconds.

I can get it to work in an odd sort of way like this:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim dt As Integer

dt = New Date().Subtract(TextBox2.Text).TotalSeconds.ToString

TextBox1.Text = dt.ToString

End Sub





But, if you run this and have the above time in Textbox2 ( 01:00:00 PM) it will show -46800 seconds in Textbox1.

I have tried several variations of the Date function, but, it appears that only the .Subtract function has the .TotalSeconds
function.

And as noted, it gives a negitive number instead of a postive number.

Any suggestions ? ( besides running as far away from the DOS based Dataflex database as I can :)

james
 
J

james

I knew it, as soon as I posted this, I would find the answer (not always that way though).

Here is what I came up with, not too complicated, and works:

Dim dt As Date

dt = TextBox2.Text

TextBox1.Text = (dt.Ticks / 10000000).ToString


Tested and so far, works good. I'm sure I will find a way to kill it ( if my users don't first!)
james
 
J

james

Herfried K. Wagner said:
\\\
Dim d As Date = #01:00:00 PM#
MsgBox(CStr(d.TimeOfDay.TotalSeconds))
///


Thanks Herfried, an even better (and shorter) way to do it.
james
 
H

Herfried K. Wagner [MVP]

james said:
I am working with a very old database system (building an import/export
routine) that stores the time in seconds. I have been able to convert the
seconds to correct time (thanks to a lot of help in this group).
But, I need to be able to write back the time of day to the db in seconds.
Example:
01:00:00 PM should be 46800 seconds.

\\\
Dim d As Date = #01:00:00 PM#
MsgBox(CStr(d.TimeOfDay.TotalSeconds))
///
 

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