DateDiff...

Ariez

Centurion
Joined
Feb 28, 2003
Messages
164
Visual Basic:
Dim myTime As DateTime
myTime = DateTimePicker1.Text

this gives me a big number when i should have a few secs
Visual Basic:
TextBox1.Text = DateDiff(DateInterval.Second, Now(), DateAdd(DateInterval.Second, CType(myTime.ToOADate(), Double), System.DateTime.Today))

And this gives me a big number too
Visual Basic:
TextBox1.Text = DateDiff(DateInterval.Second, Now(), myTime)

I need to get the diff in secs between a time #7:35:04 PM# kept in myTime and Now()...
Anyone could help on this?
 
this does it..
Visual Basic:
TextBox1.Text = DateDiff(DateInterval.Second, Now(), DateAdd(DateInterval.Second, (Mytime.Hour * 60 * 60) + (Mytime.Minute * 60) + (Mytime.Second), System.DateTime.Today))

is there a more elegant way to convert a time #hh:mm:ss# into seconds?
 
Last edited:
this does it too and looks good...
Visual Basic:
SecDiff = DateDiff(DateInterval.Second, Now(), DateTime.Parse(Mytime))
thanks anyways...
(Almost felt like taking my shoe off and smash some statue too!!!!:p)
 
Last edited:
You should not use the DateDiff function, as it is a VB6 compatability
function. You should use the TimeSpan class quwiltw said. For example,
Visual Basic:
Dim time1 As DateTime = DateTime.Parse("November 27 1987")
Dim ts As New TimeSpan(365, 55, 3, 4)
Dim newTime As DateTime = time1.Add(ts)
This will take the date 11/27/87 and add 365 days, 55 hours, 3 minutes
and 4 seconds to it.
 
VolteFace,
I got that class instance with a timer in it and a scheduled event in this format #hh:mm:ss tt#.
On every tick event, now() is compared to the schedule.
if the diff between now() and the schedule <0 the the event is fired and the timer disabled.
How do I compare now() and the schedue with the timeSpan?

(are you into poster or statue shoe smashing in Ontario?)
 
You can use the Ticks property of the Date returned by Now()
to generate a TimeSpan, and use the Subtract function of the date
you wish to subtract from. For example, this finds the amount of time
until 11/15/2005.

Visual Basic:
Dim future As New DateTime(2005, 11, 15)
Dim difference As DateTime

difference = future.Subtract(New TimeSpan(Now.Ticks))
 
New stuff is good, i'll try to use it.
This forum has helped me a lot.
Thanx for the spirit...
 
Back
Top