convert seconds to HH:MM

G

Guest

I'm getting my data from my database in seconds, 3600, how can i convert that
to time such as 1:00 pm?
 
G

Guest

I'll check that out, but i've seen it done in 2 lines of code as well and now
i can't find that snippet again.
thx
 
C

Cor Ligthert

Mike,
I'll check that out, but i've seen it done in 2 lines of code as well and
now
i can't find that snippet again.

In the sample in the link it is one line of code, however maybe can you as
in that break it up in two than it looks like two.

MessageBox.Show(TimeSpan.FromSeconds(3600).ToString)

:)

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Mike,
I normally use TimeSpan.FromSeconds (as Cor suggested):

Dim ts As TimeSpan = TimeSpan.FromSeconds(3600)

If you want it as a "Date" I normally add the TimeSpan to a "known"
DateTime.

Dim dt As DateTime = DateTime.MinValue.Add(ts)

Alternatively you can add the seconds to a "known" DateTime.

Dim ts As DateTime = DateTime.MinValue.AddSeconds(3600)

Hope this helps
Jay
 
G

Guest

will these work with a dataitem from a dataset?


Jay B. Harlow said:
Mike,
I normally use TimeSpan.FromSeconds (as Cor suggested):

Dim ts As TimeSpan = TimeSpan.FromSeconds(3600)

If you want it as a "Date" I normally add the TimeSpan to a "known"
DateTime.

Dim dt As DateTime = DateTime.MinValue.Add(ts)

Alternatively you can add the seconds to a "known" DateTime.

Dim ts As DateTime = DateTime.MinValue.AddSeconds(3600)

Hope this helps
Jay
 
J

Jay B. Harlow [MVP - Outlook]

Mike,
Yes of course they do.

Obviously you may need to convert types to/from the parameters expected &
returned.


The DataSet supports TimeSpans, however I have not tried getting them into &
out of a database...


Hope this helps
Jay
 

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