• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

date range question

Hello all,

I have an MS SQL 2K DB with a date feild.  (Tracks events that are going to happen for that week, M-F)

On a web page, I want to be able to display all the records that take place that week, none before or after.  The web page will be viewed everyday, so it will always need to go back to the beginning of the week, monday - and display records for that day, through the friday at the end of the week.  Then of course, the following monday, the web page can't show any of the records from the previous week, only the records for the business week you're currently in the middle of.

I hope I've explained it well, I'll specify if anyone has questions.

Thanks in advance.
0
Rush_2112
Asked:
Rush_2112
  • 2
1 Solution
 
Rush_2112Author Commented:
points increased**
0
 
danrosenthalCommented:
Use this code to determine the start date for your date range (which will always be a Monday):
<CFSET date = dateformat(now(),'m/d/yy')>
<CFSET displaydate = dateadd("d",-dayofweek(date-1)+1,date)>

Now, in your query grab all records where the dates are greater than displaydate and less than the displaydate + 5 days (through Friday). Although I would add 7 days to show any events on the weekend. But you can do whatever you want.
SELECT ...
FROM ...
WHERE datefield >= #displaydate#
AND datefield < #dateadd("d",5,displaydate)#
 
-Dan
0
 
Rush_2112Author Commented:
Dan,

This works perfectly!! Thank you!!

(This will still pull all of Mon-Fri data, even on a tuesday - right?)  In other words, it will still pull from dates that have past if it's in this week, correct?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now