Converting Double to Date

  • Thread starter Thread starter Brian P. Hammer
  • Start date Start date
B

Brian P. Hammer

All,

I have a function which returns a double and is show in a label. I need to convert the double to a time format. For example, if my double is 1.73 then the time should be 2 hours and 13 minutes. How can I go about this?

Thanks,
Brian P. Hammer
 
Use TimeSpan.FromHours

BTW, please don't post in HTML. Use plain text

/claes


****************************************
All,

I have a function which returns a double and is show in a label. I need to
convert the double to a time format. For example, if my double is 1.73 then
the time should be 2 hours and 13 minutes. How can I go about this?

Thanks,
Brian P. Hammer
 
Brian P. Hammer said:
I have a function which returns a double and is show in a label. I
need to convert the double to a time format. For example, if my
double is 1.73 then the time should be 2 hours and 13 minutes.
How can I go about this?

Why would 1.73 mean 2 hours and 13 minutes? That suggests that the unit
of measurement is 76.87 minutes or so, which seems very odd to me. If
you can give more of an idea of the conversion you want, I'm sure we
can help.
 
1 hour and 73 minuets or 1 hour and 1 hour and 13 minutes.

Anything that is above 60 needs to be added as an hour and then start back
over 0 minutes.

Here is what I do: I determine a distance between a start and end Latitude
and Longitude, divide it by an aircraft cruise speed, add (subtract) any
head winds and divide that by 24. This gives me a time that it would take to
make the distance. I think I might have figured it out below. It seems to
work.


Function ToDateTime(ByVal distance As Double) As DateTime
ToDateTime = Date.FromOADate(distance /
(ToDouble(Me.txtCruiseSpeed.Text) + ToDouble(Me.txtWind.Text)) / 24)
ToDateTime = ToDateTime.AddMinutes(Me.txtClimb.Text)
ToDateTime = ToDateTime.AddMinutes(Me.txtTaxi.Text)

Return ToDateTime

End Function


Does this look correct to you?

Thanks,

Brian P. Hammer
 
Thanks Claes, I think I have it figured it out but will read about timespan.

What's the deal with HTML? I did not know there was an issue.

I have to use HTM in other NG postings I make. Sometimes forget to switch.
 
Brian P. Hammer said:
1 hour and 73 minuets or 1 hour and 1 hour and 13 minutes.

Anything that is above 60 needs to be added as an hour and then start back
over 0 minutes.

So you're not really thinking of it as a quantity, you're thinking of
it as the decimal representation of the quantity. That ends up with
some very strange properties such as discontinuity. For instance:

1.99 = 3 hours and 19 minutes
2.00 = 2 hours

So adding a minute to 3 hours and 19 minutes actually takes away 1 hour
and 19 minutes...

Similarly, consider 1.5 hours: that's 1 hour and 50 minutes, right?
Divide by two and you get 0.75, which is 1 hour and 15 minutes, right?
Very strange...
Here is what I do: I determine a distance between a start and end Latitude
and Longitude, divide it by an aircraft cruise speed, add (subtract) any
head winds and divide that by 24. This gives me a time that it would take to
make the distance. I think I might have figured it out below. It seems to
work.

Doing arithmetic on the kind of mapping you've described above won't
work in any sensible way, due to the discontinuities pointed out above.
 
What newsgroups require that you post in HTML?
I've never seen one and I've been using newsgroups
since 1992!

Posting in HTML is generally frowned upon in the newsgroup
community since it is not rendered the same way across
different platforms. There are even newsreaders that can't
handle it at all so all they see is an error message.
And then there's also the virus thing...

It's just an advice. Even if you continue posting in HTML
I will still answer your questions (if I can).


/claes
 
Thanks, I was thought it might be a platform issue.

The NG is for my education at the University of Phoenix. We use Outlook
Express to "Go to Class" and it requires us to post in HTML, mainly to keep
formatting the same when we write papers.
 
Back
Top