chadmanvb
asked on
Help with Timespan diff in vb.net
I'm trying to get the difference of 2 dates in min or seconds. When I check the dates, they are both correct with the correct time. When I try to get the difference of the 2, it's not correct. Am I doing this wrong?
Dim strFileInfo As New System.IO.FileInfo("C:\tes tfile.txt" ) 'get file info
Dim dateDiff As TimeSpan = DateTime.Now.Subtract(strF ileInfo.La stWriteTim e.Date)
MsgBox(strFileInfo.LastWri teTime.Tim eOfDay.ToS tring & " " & Date.Now.TimeOfDay.ToStrin g & " " & dateDiff.Seconds.ToString)
If dateDiff.Seconds >= 120 Then 'if older than 2 min, dont use it. info is not current
Dim strFileInfo As New System.IO.FileInfo("C:\tes
Dim dateDiff As TimeSpan = DateTime.Now.Subtract(strF
MsgBox(strFileInfo.LastWri
If dateDiff.Seconds >= 120 Then 'if older than 2 min, dont use it. info is not current
ASKER
I'm still not getting this to work. Here is what I get when I do TotalSeconds.
21:04:49.0220256 21:10:13.5014703 76213.5004702
when I do seconds I get this. This will always show me the seconds in the date.now.timeofday
21:04:49.0220256 21:10:55.2506448 55
I'm sure I'm missing something simple here.
21:04:49.0220256 21:10:13.5014703 76213.5004702
when I do seconds I get this. This will always show me the seconds in the date.now.timeofday
21:04:49.0220256 21:10:55.2506448 55
I'm sure I'm missing something simple here.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much! I knew it was something simple.
Open in new window
Note: Property Seconds returns only the Seconds component of the TimeSpan.