Working with >

  • Thread starter Thread starter John
  • Start date Start date
J

John

Can someone explain why this works:

i = DateDiff("d", dBackUp, Now)
If i > 30 Then

and this:

If DateDiff("d", dBackUp, Now) > 30 then

doesn't?

Thanks.
John
 
John,

Can you please give a specific example? Or otherwise explain what you
mean by "doesn't work"? Thanks.
 
Works for me (Access 2002):

Does this work for you?

Public Sub IfTest()
Dim d1 As Date, d2 As Date
Dim i As Integer

d1 = #1/1/2008#
d2 = Date

i = DateDiff("d", d1, d2)
If i > 30 Then
MsgBox "Assigned to variable - works"
End If
If DateDiff("d", d1, d2) > 30 Then
MsgBox "Datediff in comparison - works"
End If
End Sub

It also works if I assign d2 = Now (without changing the type declaration of
i - which should not be required since DateDiff returns an integer)

Rob
 
Steve,

If the outcome of DateDiff("d", dBackUp, Now) is greater than 30 then the
code:

If DateDiff("d", dBackUp, Now) > 30 then
msgbox "blabla"
endif

doesn't show the "blabla".
When I use the i variable as shown below it does show me the "blabla".

John
 
Thanks Rob, Steve,

Yes this works for me and my own code works now as well...
I think I should get some sleep...;-)

John
 
John,

It has occurred to me that It just may have been an isolated incident
related to the use of Now() function. Depending on the dates you were
comparing. The Now() function includes a time component. So the
difference between Now() and a date 30 days ago is more than 30 days, if
you catch my drift. Whereas your other example, casting the type as
Integer, would remove the time component, making the comparison an exact
number of days.
 
Thanks for the insight.
John

Steve Schapel said:
John,

It has occurred to me that It just may have been an isolated incident
related to the use of Now() function. Depending on the dates you were
comparing. The Now() function includes a time component. So the
difference between Now() and a date 30 days ago is more than 30 days, if
you catch my drift. Whereas your other example, casting the type as
Integer, would remove the time component, making the comparison an exact
number of days.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top