Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find the difference between two datetimes in seconds

I have had a quick look around and I can't find an answer to this in vb.net or something that I can convert into vb.net.

I have two DateTimes in vb.net's 'Date' class. I would like to find the difference between these in seconds. I can do a-b, but the answer will still be a 'date'. I can use .seconds .minutes etc. and multiply but I will hit problems when I come to months.

Is there a simple way to do this, or do I need to write some elaborate-ish code?

Many Thanks

like image 515
Pezzzz Avatar asked Sep 21 '12 10:09

Pezzzz


2 Answers

Subtract the DateTime values from each other - the returned type will be a TimeSpan.

Get the TotalSeconds value from it.

(date1 - date2).TotalSeconds
like image 100
Oded Avatar answered Nov 18 '22 16:11

Oded


There actually is also a function made for this DateDiff(DateInterval.Second, d1, d2)

like image 26
KekuSemau Avatar answered Nov 18 '22 15:11

KekuSemau