I would have doneWHERE ProfileCreationDate >= DATEADD(Day, -7, GetDate())
(GetDate() is a SQL function for current Date AND Time - so that will all happen at the SQL end, rather than based on the Web Server time. That only matters if the time is different on the Web Server and the SQL Server!! If the date/time for ProfileCreationDate is automatically added by SQL then I would user SQL time, if it is added by your APP instead then maybe I would use Web Server time. What if one is on Daylight Saving Time and the other not? Or the servers are in different countries?? Anyway, that may not be a problem you need to worry about!!!!)Next problem is that DATEADD (and DATEDIFF) will add a DAY but keep the TIME part the same ... when you say "Last 7 days" I expect you mean "Any records in the last 7 days and today, so far" and that means starting at midnight 7 days ago.For example if I doSELECT GetDate() AS TimeNow, DATEADD(Day, -7, GetDate()) AS TimeBefore
I getTimeNow TimeBefore----------------------- -----------------------2015-05-02 08:50:03.893 2015-04-25 08:50:03.893
There are various ways of getting "Midnight" on a date, usually involving string manipulation, but this is the most efficient for SQL as it only uses integer maths, no [slower] string conversionSELECT GetDate() AS TimeNow, DATEADD(Day, 0, DATEDIFF(Day, 0, GetDate()) - 7) AS TimeBeforeTimeNow TimeBefore----------------------- -----------------------2015-05-02 08:52:22.313 2015-04-25 00:00:00.000
so if your APP will use the Date/Time on the SQL Server then your code would need to be:select Name ,Profession,ProfileCreationDate from tblRegistration where ProfileCreationDate >= DATEADD(Day, 0, DATEDIFF(Day, 0, GetDate()) - 7)order by ProfileCreationDate DESC