JuniorBee
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()
strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID="&Session(UserID)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID="&Session(UserID) &" AND [dateTime] >= '"& DateAdd('h', -24, Date()) &"'"
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()"
strsqlg = "SELECT COUNT(*) AS SaleCount FROM [tblSales] WHERE sellerID=" & Session(UserID) & " AND [dateTime] BETWEEN GETDATE() - 1 AND GETDATE()"
ASKER
Thanks for all your answers. First one worked so I accepted that one. =)
Not a problem. Glad you got your problem solved.