Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
werosen1
Starting Member
2 Posts |
Posted - 2006-04-17 : 13:05:07
|
I'm trying to write an SQL query that identifies today's date, and then provides the date range for that date's week, so I can return all my database records that fall in that week's date range and display them in my ASP page.Is there a way to do this?Regards |
|
Hommer
Aged Yak Warrior
808 Posts |
Posted - 2006-04-17 : 15:47:21
|
Depending on where you want to put your code, it should be some thing like this:1. from the entered date, get the day of the week, i.e. from 4/17/06, get Monday,2. based on above day of week value, decide how many days to take. i.e., if it is Monday, you want from Monday to Friday, then you add 5 day to get the ending date for the week, if it is Tues, you add 4 days to get to Friday, and subtract 1 day to get Monday...3. query your data based on the beginning and ending dates of that week. You could do this in t-sql if your data are in sql server, or in VBA if it is access, or VBScript if it is in ASP. |
 |
|
werosen1
Starting Member
2 Posts |
Posted - 2006-04-17 : 16:01:39
|
Thanks for the reply. I started down the road you suggest, but then ran across a simpler approach that works well for my purpose.Here it is in case it's useful to you.SELECT * FROM [dbtable] WHERE (((Format([datefield],'yyyy-ww'))=Format(Date(),'yyyy-ww')));Obviously specific field names can be substituted for '*'. |
 |
|
|
|
|
|
|