473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calendar: x weeks ago always starting on a Sunday

The result of the query should be all dates from today - 5 weeks ago, where the first day is a Sunday using a calendar table specifically for this business:

The current week is defined as w/e 15th Jan and it's the 5 weeks back from then so start w/e 11th Dec

e.g.

select distinct day_date, day_name, week_number, weekstart_date
from
calendar
where
day_date between (curdate() - INTERVAL 35 day) and curdate()

returns data from

09/12/2011 - today, which is fine, but the first date I am interested in is the Sunday:

day_date day_name week_number weekstart_date weekend_date
2011-12-09 00:00:00 Friday 50 2011-12-05 00:00:00 2011-12-11 00:00:00
2011-12-10 00:00:00 Saturday 50 2011-12-05 00:00:00 2011-12-11 00:00:00
2011-12-11 00:00:00 Sunday 51 2011-12-05 00:00:00 2011-12-11 00:00:00

.....


2012-01-12 00:00:00 Thursday 2 2012-01-09 00:00:00 2012-01-15 00:00:00
2012-01-13 00:00:00 Friday 2 2012-01-09 00:00:00 2012-01-15 00:00:00


What SQL do I write to ensure that the first Sunday will always be selected as the first day of the date range?
Jan 13 '12 #1
1 2041
Rabbit
12,516 Expert Mod 8TB
Well you need to account for the current date's weekday.

You need to take 35, add 7, (or just take 42) and then subtract the weekday() of the current date. With the exception of sunday of course.
Jan 13 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lee Falataco | last post by:
I have the tables set up in Access, viewing in column format on ASP pages but now the company wants the schedule reports to be in a wall-calendar type format. I've searched and found calendar...
7
by: Dennis M. Marks | last post by:
Before you say anything I know that there are many monthly calendars out there. I did it for the challenge. My calendar was COMPLETLY done from scratch with no copied code except for the dynamic...
0
by: John Baker | last post by:
Hi: I am trying to put together a report that looks like a refrigerator calendar. It will show one line for each week in the month (always starting on a monday). If the month starts on some...
2
by: patrick delifer | last post by:
I am binding some data to a calendar control. Since I don't want to return all the Data from the DB, I would like to return only the data for the current view of the calendar. The calendar has...
0
by: Vincent | last post by:
Does .NET Framework FCL have any function to get week of Month?? Like, November 1 Saturday is 1st week, then November 2 Sunday is 2nd Week, November 8 Saturday is 2nd week, November 9 Sunday is the...
2
by: todd.freed | last post by:
Hi All, I am using the <asp: Calendar> object. In the OnDayRender event handler I am putting text into certain day boxes, and leaving others blank. The effect is that some months have no...
4
by: rnash1 | last post by:
I am tring to get a calendar control to just update to the current date when the form is opened, But for some reason cant get it to work. The calendar is always on the same date. This is what I put...
1
by: jamesker | last post by:
Hi, I have a continuous form with a date field in it. beside the date field, i've made a command button that when pressed, displays a calendar form which allows users to choose a date, once a...
7
by: William (Tamarside) | last post by:
Please, if you have the time and knowledge to help me I'd truly appreciate it! I need to build a calendar page that displays available/unavailable info from a DB and colour a cell according to...
14
by: Tommy Jakobsen | last post by:
Hi. Is there a method in .NET that takes "year" as an argument and returns the total number of weeks in that year? For culture da-DK (Danish). Thanks in advance. Tommy.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.