|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
diference between to dates in hoursI have two dates that I would like to compare. The two should be within one hour from each other. Sometimes date x is older and sometimes date y is older. I tried: For example: dX_date = 01-02-2006 10:45:00 dY_date = 01-02-2006 11:12:00 If DateDiff("h", dX_date, dY_date) < 1 Then msgbox"Within an hour" Endif but then I can get a negative number and I get a False. Regards Marco <vonclausow***@gmail.com> wrote in message
Show quoteHide quote news:1138916404.619145.280050@g44g2000cwa.googlegroups.com... You can use the ABS function to get the absolute value (gets rid of the > Hi All, > > I have two dates that I would like to compare. > The two should be within one hour from each other. Sometimes date x is > older and sometimes date y is older. I tried: > > For example: > dX_date = 01-02-2006 10:45:00 > dY_date = 01-02-2006 11:12:00 > > If DateDiff("h", dX_date, dY_date) < 1 Then > msgbox"Within an hour" > Endif > > but then I can get a negative number and I get a False. > > Regards > > Marco negative sign) '===== Private Sub Command1_Click() Dim dX_date As Date Dim dY_date As Date Dim lDifference As Long dX_date = #1/2/2006 10:45:00 AM# dY_date = #1/2/2006 11:12:00 AM# 'Hours lDifference = Abs(DateDiff("h", dX_date, dY_date)) MsgBox "Difference = " & lDifference, , "Hours" End Sub '===== -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm Adding to that, I would get the difference in minutes and check
for 60. Saga Show quoteHide quote "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message news:eGmlnIEKGHA.3276@TK2MSFTNGP09.phx.gbl... > <vonclausow***@gmail.com> wrote in message > news:1138916404.619145.280050@g44g2000cwa.googlegroups.com... >> Hi All, >> >> I have two dates that I would like to compare. >> The two should be within one hour from each other. Sometimes date x >> is >> older and sometimes date y is older. I tried: >> >> For example: >> dX_date = 01-02-2006 10:45:00 >> dY_date = 01-02-2006 11:12:00 >> >> If DateDiff("h", dX_date, dY_date) < 1 Then >> msgbox"Within an hour" >> Endif >> >> but then I can get a negative number and I get a False. >> >> Regards >> >> Marco > > You can use the ABS function to get the absolute value (gets rid of > the negative sign) > '===== > Private Sub Command1_Click() > Dim dX_date As Date > Dim dY_date As Date > > Dim lDifference As Long > > dX_date = #1/2/2006 10:45:00 AM# > dY_date = #1/2/2006 11:12:00 AM# > > 'Hours > lDifference = Abs(DateDiff("h", dX_date, dY_date)) > > MsgBox "Difference = " & lDifference, , "Hours" > > End Sub > '===== > > -- > Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. > DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm > Freeware 4 color Gradient Frame? > http://www.vbsight.com/GradFrameCTL.htm > |
|||||||||||||||||||||||