date range question

Posted on 2006-04-21
Last Modified: 2013-12-24
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.
Question by:Rush_2112
    LVL 1

    Author Comment

    points increased**
    LVL 15

    Accepted Solution

    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)#
    LVL 1

    Author Comment


    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?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now