• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • 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.
  • 2
1 Solution
Rush_2112Author Commented:
points increased**
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.
FROM ...
WHERE datefield >= #displaydate#
AND datefield < #dateadd("d",5,displaydate)#
Rush_2112Author Commented:

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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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