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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql and DateAdd

Status
Not open for further replies.

jongag1

Technical User
Feb 1, 2002
65
NL
Hello,

I use the below query to display the count for the records which where entered the last 30 minutes.
The problem I have is that it doesn't go over the night.
We enter records from 21.00 hours until 09.00 hour the next day.
When I use this code it doesn't go to the day before.
For example, we run the code at 00:10 on day X, it doesn't display the records from 23:40 from day X-1.

SELECT Count(POSTALCODE) FROM CLIENTS WHERE (((DATE)>DateAdd("n",-30,Now())) AND (Left(POSTALCODE,4)= Left('[PC]',4)));

Can somebody please help me?

Kind regards,
Age
 
Oops, forgot the code tags...

Code:
SELECT Count(POSTALCODE) FROM CLIENTS WHERE (((DATE)>DateAdd("n",-30,Now())) AND (Left(POSTALCODE,4)= Left('[PC]',4)));
 
By the way, DATE is in the following format:
07/06/2006 21:01:13
 
if your dates are actually in that format then they are probably VARCHAR, not DATETIME

convert to DATETIME and bob's your uncle, your query will work

while you're at it, choose a different column name, because DATE is a reserved word

by the way, LEFT('[PC]',4) can be simplified to '[PC]'





r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top