//  home   //  advanced search   //  news   //  categories   //  sql build chart   //  downloads   //  statistics
 ASP FAQ 
Home
ASP FAQ Tutorials

   8000XXXX Errors
   Alerts
   ASP.NET 2.0
   Classic ASP 1.0
      COM / ActiveX Components
      Forms
      General Topics
      Date/Time Routines
      Email Scripts & Info
      Files/Directories & FSO
   Databases
   General Concepts
   Search Engine Optimization (SEO)

Contact Us
Site Map

Search

Web
aspfaq.com
tutorials.aspfaq.com
classicasp.aspfaq.com

ASP FAQ Tutorials :: Classic ASP 1.0 :: Date/Time Routines :: Given a date, how do I find the beginning and end of that week?


Given a date, how do I find the beginning and end of that week?

Assuming you have a standard work week, let's say you have a variable that represents a date, and you want to find out the first and last day of that week (the preceding Sunday, and the upcoming Saturday). 
 
VBScript 
 
<% 
    d = "2003-11-01" 
    response.write dateadd("d", 1 - weekday(d), d) 
    response.write "<P>" 
    response.write dateadd("d", 7 - weekday(d), d) 
%>
 
T-SQL 
 
DECLARE @d SMALLDATETIME 
SET @d = '2003-11-01' 
SELECT DATEADD(DAY, 1-DATEPART(dw, @d), @d) 
SELECT DATEADD(DAY, 7-DATEPART(dw, @d), @d)
 

 
If you don't have a standard week (e.g. day 1 = Monday), you could just adjust the numbers used for the calculations (1 and 7). 
 
If you need to find the start of the *business* week, you can add 1 to the first result and subtract one from the second, for example: 
 
DECLARE @d SMALLDATETIME 
SET @d = '2003-11-02' 
SELECT DATEADD(DAY, 2-DATEPART(dw, @d), @d) 
SELECT DATEADD(DAY, 6-DATEPART(dw, @d), @d)
 
However, your calculations might not be so simple, because this obviously doesn't take into account holidays and other interruptions in a typical work week. See Article #2453 for a demonstration of the use of a calendar table to help count business days.

Related Articles

Can I get millisecond accuracy in ASP?
Can I make VBScript format dates for me?
Could I get a little help with dates?
Given two dates, how do I determine an age?
How do I calculate dates, such as the first day of the month?
How do I convert a DATEDIFF to days, hours, and minutes?
How do I convert a timespan, in seconds, to HH:MM:SS?
How do I convert local time to UTC (GMT) time?
How do I count the number of business days between two dates?
How do I delimit/format dates for database entry?
How do I determine the number of seconds since 1/1/1970?
How do I display time in military format?
How do I implement a calendar / datepicker in ASP?
How do I select time only from a DATETIME column?
Why do I have problems inserting NOW() into a database?
Why does JavaScript's document.lastModified() not work in ASP files?

 

 


Created: 11/8/2003 | Last Updated: 11/8/2003 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (370)

 

Copyright 1999-2006, All rights reserved.
Finding content
Finding content.  An error has occured...