| Author |
Topic |
|
westmich
Starting Member
35 Posts |
Posted - 2004-09-06 : 14:17:05
|
| I am creating a view, but I only want records where the DateCreated field is within the last 7 days. I'd normally do this server-side in ASP but I'd like to keep it in a view if possible.WestmichSmart Web Solutions for Smart Clientshttp://www.mindscapecreative.com |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-09-06 : 14:38:02
|
| WHERE DateCreated >= CONVERT(VARCHAR,DATEADD(DD,-7,GETDATE()),101)MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-09-06 : 15:34:19
|
| WHERE DateCreated >= CONVERT(DATEADD(DD,-7,convert(varchar(8),GETDATE(),112))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-09-06 : 17:56:19
|
| WHERE DateCreated >= GETDATE() - 7rockmoose/* Chaos is the nature of things...Order is a lesser state of chaos */ |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-09-06 : 19:09:45
|
| okderrickleggett - that only works on mm/dd/yyyy systemsrockmoose - that will give things created later than the current time time 7 days ago and only if datecreated is a datetime. Might be what westmich wants but I doubt it.But I suspect you knew that.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-09-06 : 21:55:35
|
He's in the US. The chance of him not using mm/dd/yyyy is slim. It is possible though.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-09-07 : 04:00:57
|
| Yes, " WHERE DateCreated >= GETDATE() - 7" is only for datetime datatype,just added that for completeness in case DateCreated really is a datetime.And it treats 7 days ago literally, i.e where DateCreated occurred within 168 hours before now.westmich - For within 7 days back and datetime datatype you could use:WHERE DateCreated >= DATEADD(DAY,-7,FLOOR(CAST(GETDATE() AS FLOAT)))rockmoose/* Chaos is the nature of things...Order is a lesser state of chaos */ |
 |
|
|
westmich
Starting Member
35 Posts |
Posted - 2004-09-07 : 10:43:07
|
| Thanks for the help. I am not too concerned on the time, so I think rockmosse's solution will probaly work best.WestmichSmart Web Solutions for Smart Clientshttp://www.mindscapecreative.com |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-07 : 11:00:06
|
| or:WHERE DateCreated >= dateadd(dd,-7,datediff(dd,0,getdate()))- Jeff |
 |
|
|
|