| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 110831 | 2010-07-03 03:11:00 | SQL select last 5 days | Mike (15) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 1115567 | 2010-07-03 03:11:00 | I want to select the last 5 days records using MS SQL (going to use PHP to do it)... how would I do that? I have a date field in the format YYYYMMDD (although it is a String field type). Any suggestions? Thanks, Mike. |
Mike (15) | ||
| 1115568 | 2010-07-03 03:36:00 | select ... from [tablename] where [date column] > convert(varchar(8), dateadd(dd, -5, getdate()), 112); | somebody (208) | ||
| 1115569 | 2010-07-03 03:44:00 | Thanks somebody, that worked select * FROM [mytable] where [date_field] > convert(varchar(8), dateadd(day, -5, getdate()), 112); (what does the 112 mean??) as did SELECT * FROM [mytable] WHERE (DATEDIFF(day, [date_field], GETDATE()) < 5)(which I was about to post when I saw your reply :D Cheers, Mike. |
Mike (15) | ||
| 1115570 | 2010-07-03 04:04:00 | 112 is a date format. See msdn.microsoft.com | somebody (208) | ||
| 1 | |||||