Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default Value=Now(), datediff not giving resutls 1

Status
Not open for further replies.

JDRoss

MIS
Sep 27, 2002
67
0
0
IE
I have a datetimestamp field of type Date/Time in a table, which is updated with the default value, Now() from the system clock when a record is created. I want to show in query and report when a record was created or entered.

I have tried the following datediff statement to show entries that have been made in the last 90 days, but I get no results.
Code:
DateDiff("d",Date(),[table1]![DateTimeStamp)>=90
Can you help?

John
 
Try:

Code:
Date()-[table1]![DateTimeStamp] >= 90

Subtracting two dates in VBA gives an integer result, which is the number of days between them.


Bob Stubbs
 
John,

This should fix you up:

Code:
[table1]![DateTimeStamp] >= (date() - 90) & " " & #00:00#

& " " & #00:00# ensures you get all entries that are exactly 90 days old by setting the time of day.



HTH,
Bob [morning]
 
John,

"upon further review..."

DateDiff(interval,date1,date2) calculates FROM date1 to date2. If date1 is the newer date, you get a negative number as a result - which will always fail the >= 90 comparison.

Code:
DateDiff("d",[table1]![DateTimeStamp],date())>=90

WILL work.

OR:
Code:
int(DateDiff("d",Date(),[table1]![DateTimeStamp))>=90

If you have entries exactly 90 days ago, I don't know whether the time portion might keep some records from being returned.



HTH,
Bob [morning]
 
Thanks Bob & Bob

None of those suggestions seem to work for me, though I now have a better understanding of what datediff is doing. The datediff function works well on other date fields I have, but not on the default value=Now() one.

I am wondering if I set the default=date() rather than Now(), will it make the difference in calculating?

John
 
Code:
>=(Date()-90) & " " & #00:00:00#

Thanks Bob, I tried this again and it works perfectly. Thank you so much.

Regards

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top