DateDiff...

Ariez

Well-known member
Joined
Feb 28, 2003
Messages
164
[VB]

Dim myTime As DateTime
myTime = DateTimePicker1.Text
[/VB]

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

And this gives me a big number too
[VB]
TextBox1.Text = DateDiff(DateInterval.Second, Now(), myTime)
[/VB]

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..
[VB]
TextBox1.Text = DateDiff(DateInterval.Second, Now(), DateAdd(DateInterval.Second, (Mytime.Hour * 60 * 60) + (Mytime.Minute * 60) + (Mytime.Second), System.DateTime.Today))
[/VB]

is there a more elegant way to convert a time #hh:mm:ss# into seconds?
 
Last edited by a moderator:
this does it too and looks good...
[VB]
SecDiff = DateDiff(DateInterval.Second, Now(), DateTime.Parse(Mytime))
[/VB]
thanks anyways...
(Almost felt like taking my shoe off and smash some statue too!!!!:p)
 
Last edited by a moderator:
You should not use the DateDiff function, as it is a VB6 compatability
function. You should use the TimeSpan class quwiltw said. For example,
Code:
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.

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

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