Access 2000 - Custom week calculation

Posted on 2011-05-12
Last Modified: 2012-05-11
Dear Experts,

I need to calculate weeks in Access from date following such logic

- if the date is smaller than today --> week0
- if the date is this week --> week0
- if the date is next week --> week1
- if the date is after next week --> week2

Basically the actual week is from monday to sunday, so as today is 2011-05-13 that is 6 by this formula - TodayWeekday: Weekday(Date()). This can have importance that the next week always starts at Monday so when the TodayWeekday is 2.

Question by:csehz
    LVL 92

    Accepted Solution

    If you would want the week number to keep increasing as you extend out into the future:

    SELECT Date() AS Today, SomeDate, 
        "week" & DateDiff("ww", Date(), IIf(SomeDate < Date(), Date(), SomeDate), 2) AS WeekNum
    FROM SomeTable

    Open in new window

    LVL 1

    Author Closing Comment

    This is perfect to me, thanks very much

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

    732 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

    17 Experts available now in Live!

    Get 1:1 Help Now