Link to home
Start Free TrialLog in
Avatar of JuniorBee
JuniorBeeFlag for United States of America

asked on

Returning records created within the last 24 hours

I am trying to write this query in ASP for a MSSQL database so that it finds the records with the field 'datetime' in the past 24 hours.  Right now it just return the one with todays date:

strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID="&Session(UserID)&" AND dateTime ="&date()
ASKER CERTIFIED SOLUTION
Avatar of kelvinwkw
kelvinwkw
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID="&Session(UserID)&" AND [dateTime] >= '"& DateAdd('h', -24, Date()) &"'"
Avatar of Anthony Perkins
strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID=" & Session(UserID) & " AND [dateTime] >= GETDATE() - 1"
Or strictly speaking:
strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID=" & Session(UserID) & " AND [dateTime] BETWEEN GETDATE() - 1 AND GETDATE()"
Avatar of JuniorBee

ASKER

Thanks for all your answers.  First one worked so I accepted that one.  =)
Not a problem.  Glad you got your problem solved.