Dates

  • Thread starter Thread starter Dennis D.
  • Start date Start date
D

Dennis D.

Hello:
Been working on this way too long.

DateDiff returns a Long. : Totally counter-intuitive.
Subtracting: 0400 - 0345 returns -15 : Wrong, should be +15?
Subtracting 02:00 - 00:15 with an interval of minutes returns 105 which is 2
hours minus 15 minutes, not the expected 01:45 or at least 45

Simply, there are two textboxes. Both receive a time (as a string of course)
in hours and minutes as 00:00
The first has the start time 16:00 or 04:00 pm. The second has a number of
hours and minutes to subtract from the start time, such as 00:15 or 15
minutes.

I've been studying the time structure for 2 days. It's spread all over the
resources in methods, functions, classes, keywords, you name it. You could
write a small book on it. Meanwhile, I need some help with what should be a
simple construct.

Thanks,
Dennis D.,
http://www.dennisys.com/
 
Dennis said:
Hello:
Been working on this way too long.

DateDiff returns a Long. : Totally counter-intuitive.
Subtracting: 0400 - 0345 returns -15 : Wrong, should be +15?
Subtracting 02:00 - 00:15 with an interval of minutes returns 105 which is 2
hours minus 15 minutes, not the expected 01:45 or at least 45
Try using the TimeSpan object:


Dim s As New TimeSpan(2, 0, 0)
Dim t As New TimeSpan(0, 15, 0)
Debug.WriteLine(s.Subtract(t))
 
Subtracting 02:00 - 00:15 with an interval of minutes returns 105 which is 2

In this case, 105 is correct. 12:15am to 2:00am is 1 hour and 45 minutes
or 105 minutes
 
Chris Dunaway said:
is 2

In this case, 105 is correct. 12:15am to 2:00am is 1 hour and 45 minutes
or 105 minutes

returns 105
which is 2 hours minus 15 minutes,
not the expected 01:45 or at least 45

I agree. 105 is the correct number of minutes to return from the calculation
using an interval of minutes.
 
Great: So am I to gather that there is no facility within the whole platform
structure that will subtract 10 minutes from 12AM and return 11:50PM?
I'm thinking there shouldn't be anyone working at NASA that includes
Microsoft in their resume. Is that accurate?

I've left to invent the wheel. Be back in a lightyear.

MyOg.
 
returns 105
which is 2 hours minus 15 minutes,
not the expected 01:45 or at least 45

I agree. 105 is the correct number of minutes to return from the calculation
using an interval of minutes.

I'm sorry, but I guess I don't understand your problem. When you say 02:00
- 00:15, I interpret that to read "2AM minus 12:15AM". The resulting
difference in minutes is 105 minutes.

Are you trying to take 2 AM and subtract 15 minutes to get 1:45 am? If so
then try this:

Dim dDateVar as DateTime 'Variable that holds 2AM
Dim dResult As DateTime = dDateVar.AddMinutes(-15) 'subtract 15 minutes

Or

'Create a timespan of 2 hours and 0 minutes
Dim ts As New TimeSpan(2, 0, 0)
'Subtract 15 minutes from it
Dim tsResult As TimeSpan = ts.Subtract(New TimeSpan(0, 15, 0))

'The properties of tsResult has all the info you need.

Cheers
 
For anyone interested in this thread I found a meaningful article and some
code at this location:

http://www.vbrad.com/pf.asp?p=source/src_time_routines.htm

Note that the source applies to VB 5-6. Although dated, it is still helpful.

Calculating date and time is a complex topic in any programming language. If
anyone has knowledge of similar code for doing date and time calculations in
Visual Basic.Net feel free to jump in with a link to some source code. I'm
still studying it, including: different ways to do related type conversions;
classes or modules that contain date and time functions, and handling
related exceptions and input errors.

The subject is germain to innumerable real life applications where time must
be considered. Thanks to everyone who is participating.
 
Dennis D. said:
For anyone interested in this thread I found a meaningful article and
some code at this location:

http://www.vbrad.com/pf.asp?p=source/src_time_routines.htm

Note that the source applies to VB 5-6. Although dated, it is still
helpful.

I don't understand which problems you have with dates. In opposite to VB5-6,
there's a Timespan class now that makes it easier because there's a
distinction between time spans and points in time now.

I had a (short) look at the page above.

Apart from the DateTime and Timespan types, there is System.TimeZone,
System.TimeZone.ToUniversalTime and so on.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Thanks Armin:

My experience has shown that working with dates and times is time well spent
when learning a computer language. The problem for me is to learn how to
code with dates and times, and here I am using the words generically to
include all of the members of .Net and VB.Net that include the two concepts.
That requires knowing what is involved and where it is found.

Suppose I wanted to write an International Airline Itenerary, a personal
calendar, a Logistics plan, or even to calculate the speed of the Earth
moving through space. In any event, I need to know how VB.net and the .Net
framework exposes, encapsulates, and furnishes means to input, calculate,
return and convert information related to the concepts of date and time.

The documentation included with VB.Net provides some of the knowledge
required to code practical applications, but it helps to have access to code
samples and articles that further illustrate principles, methods, and best
practices.

'-Dennis D.-'
 
Hi Dennis,

That is all new, in past we did not have that as you write.

However it is true although still not yet complete, summertimes (daylight
saving it is I believe in US) and things like that are in Microsoft Office,
but I have not seen it in the framework yet.

This is no VB.net however this things are than also nice to look at

http://www.timeanddate.com/worldclock/

Cor
 
Yes, times and dates have a long history in programming as being among the
first elements coded in program for machine (computer) use.
 
Back
Top