Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtracting Dates/Times

Status
Not open for further replies.

wadewilson1

Programmer
Sep 10, 2002
23
0
0
US
This is probably something very simple, but its just not clicking with me.

I'm trying to subtract 2 dates/times from each hoping to result in the "system" tranlsation of the dates/times.
IE("07/14/2004 08:00 AM" - "07/14/2004 00:00 AM" = 0.33333)

Does anyone know of away to do this? When I put it in code, it tells me "Operator "-" is not defined for types 'Date' and 'Date'"

Thanks!
 
try something like this

Code:
Dim d As DateTime
d = "12/07/2004 00:00:00"
TextBox1.Text = d
TextBox2.Text = Now()
TextBox3.Text = d.Subtract(Now).ToString

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
Thanks this subtracted the date/times and gave me back the number of minutes from midnight.

IE( "07/14/2004 12:15:00 PM" to "07/14/2004 12:30:00 PM" this gave me and answer of 07/14/2004 12:15:00 AM)

Do you have any idea how to get to a decimal format. I tried using Convert.ToDecimal(TextBox3.Text) but it won't allow the conversion.

 
In .NET, you'll get a TimeSpan structure when subtracting DateTime objects, on which you can look at the TotalDays property, which gives you the number of whole and fractional days. This should give you the "0.3333" that you want.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top