time comparison

neilakoga

Member
Joined
Nov 25, 2007
Messages
7
Programming Experience
1-3
ok so i've got one time in my sql database which i want to compare to the current time now. if the current time is 2 hours greater than the original time in te database i need to do something.

ie - if difference between time1(original datetime from database) is greater than 2 hours difference from time2(datetime now) then ...
do something
end if

I'm sure it's simple and my syntax is struggling in the 2 hours area, how would i represent 2 hours as a comparison?
 
anyways here's what i have so far

Dim dt1 As DateTime
dt1 = dr.Item("leadCreationDate")
Dim dt2 As DateTime = DateTime.Now
Dim xtime As TimeSpan
xtime.don't know what to do here
if datetime.Compare(dt1, dt2)
End If
 
VB.NET:
  Dim date1 As Date = YourVariableFromDataBase
  Dim date2 As Date = Now

  If DateDiff("h", date1, date2) >= 2 Then
    'Code here
  End If

The DateDiff function will compare the two, and the "h" modifier should make it look @ hours.
 
What is the code is to be repeated daily, wouldn't the time difference become more than 2? Is there anyway to solve this problem?
 
Please be clear about what you want. Are you saying that you want to test the time of day, irrespective of the date? So 1 PM last Tuesday would still be within 2 hours of 2 PM today because you're comparing only the time portion?
 
this has been solved, i'm using the datediff function. I'm storing the full datetime in sql in year/month/day/hour/minute/second format , i just format as needed to do the smaller time calculations, it's all working good though
 
Back
Top