<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.5" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: MySQL: find week start/end given week number</title>
	<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/</link>
	<description>Utterly random, incoherent and disjointed rants and ramblings...</description>
	<pubDate>Sat, 22 Nov 2008 01:44:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>

	<item>
		<title>by: Luke Maciak</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-10227</link>
		<pubDate>Tue, 23 Sep 2008 17:47:28 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-10227</guid>
					<description>@&lt;a href="#comment-10226" rel="nofollow"&gt;Sid&lt;/a&gt;: What do you mean? I think it is sort of self explanatory.

@aStart will be the date exactly a week before today
@aEnd will be a week from @aStart - which is today
@aStartlastweek will be a date 1 week prior to @aStart

And so on. When it says:

&lt;pre lang="sql"&gt;SET @foo = @bar - INTERVAL n WEEK&lt;/pre&gt;

it just means to count back n weeks from the date in @bar and put the result in @foo. The last 4 lines are just assignments.

Does that make sense?</description>
		<content:encoded><![CDATA[<p>@<a href="#comment-10226" rel="nofollow">Sid</a>: What do you mean? I think it is sort of self explanatory.</p>
<p>@aStart will be the date exactly a week before today<br />
@aEnd will be a week from @aStart - which is today<br />
@aStartlastweek will be a date 1 week prior to @aStart</p>
<p>And so on. When it says:</p>

<div class="wp_syntax"><div class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">SET</span> @foo = @bar - INTERVAL n WEEK</pre></div></div>

<p>it just means to count back n weeks from the date in @bar and put the result in @foo. The last 4 lines are just assignments.</p>
<p>Does that make sense?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Sid</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-10226</link>
		<pubDate>Tue, 23 Sep 2008 17:28:55 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-10226</guid>
					<description>I have a script which has the following in the beginning, can someone explains what does it mean in mysql:

&lt;pre lang="sql"&gt;SET @aStart = CURDATE() - INTERVAL 1 WEEK;  
SET @aEnd = @aStart + INTERVAL 1 WEEK;
SET @aStartlastweek = @aStart - INTERVAL 1 WEEK;
SET @aEndlastweek = @aEnd - INTERVAL 1 WEEK;
SET @aStartlast2week = @aStart - INTERVAL 2 WEEK;
SET @aEndlast2week = @aEnd - INTERVAL 2 WEEK;
SET @aStartlast3week = @aStart - INTERVAL 3 WEEK;
SET @aEndlast3week = @aEnd - INTERVAL 3 WEEK;
SET @aStartlast4week = @aStart - INTERVAL 4 WEEK;
SET @aEndlast4week = @aEnd - INTERVAL 4 WEEK;


SET @bStartNorm = 5;
SET @bEndNorm = 23;
SET @bRspCode = 999;
SET @bMaxAvg  = 120;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I have a script which has the following in the beginning, can someone explains what does it mean in mysql:</p>

<div class="wp_syntax"><div class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">SET</span> @aStart = CURDATE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> - INTERVAL <span style="color: #cc66cc;">1</span> WEEK;  
<span style="color: #993333; font-weight: bold;">SET</span> @aEnd = @aStart + INTERVAL <span style="color: #cc66cc;">1</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aStartlastweek = @aStart - INTERVAL <span style="color: #cc66cc;">1</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aEndlastweek = @aEnd - INTERVAL <span style="color: #cc66cc;">1</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aStartlast2week = @aStart - INTERVAL <span style="color: #cc66cc;">2</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aEndlast2week = @aEnd - INTERVAL <span style="color: #cc66cc;">2</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aStartlast3week = @aStart - INTERVAL <span style="color: #cc66cc;">3</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aEndlast3week = @aEnd - INTERVAL <span style="color: #cc66cc;">3</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aStartlast4week = @aStart - INTERVAL <span style="color: #cc66cc;">4</span> WEEK;
<span style="color: #993333; font-weight: bold;">SET</span> @aEndlast4week = @aEnd - INTERVAL <span style="color: #cc66cc;">4</span> WEEK;
&nbsp;
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @bStartNorm = <span style="color: #cc66cc;">5</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @bEndNorm = <span style="color: #cc66cc;">23</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @bRspCode = <span style="color: #cc66cc;">999</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @bMaxAvg  = <span style="color: #cc66cc;">120</span>;</pre></div></div>

]]></content:encoded>
				</item>
	<item>
		<title>by: Julio</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-9761</link>
		<pubDate>Thu, 31 Jul 2008 23:52:55 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-9761</guid>
					<description>i have a question... how can i group by weeks... but starting on wednesday or tuesday?</description>
		<content:encoded><![CDATA[<p>i have a question&#8230; how can i group by weeks&#8230; but starting on wednesday or tuesday?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: olivier</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-8341</link>
		<pubDate>Wed, 05 Mar 2008 21:11:46 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-8341</guid>
					<description>For iso weeks (week starting on mondays, week numbering starting at 1) you can get the first day of the week "week_id" of the year "year" using
&lt;code&gt;DATE_ADD( MAKEDATE(year,1), INTERVAL( -(((DAYOFWEEK(MAKEDATE(year,1))+1)%7)-3) + (week_id-1)*7 ) DAY)&lt;/code&gt;
simple, no ? :)</description>
		<content:encoded><![CDATA[<p>For iso weeks (week starting on mondays, week numbering starting at 1) you can get the first day of the week &#8220;week_id&#8221; of the year &#8220;year&#8221; using<br />
<code>DATE_ADD( MAKEDATE(year,1), INTERVAL( -(((DAYOFWEEK(MAKEDATE(year,1))+1)%7)-3) + (week_id-1)*7 ) DAY)</code><br />
simple, no ? <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif" alt=")" class="wp-smiley" />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Snehapadma SaaS</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-7536</link>
		<pubDate>Sun, 30 Dec 2007 04:10:46 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-7536</guid>
					<description>Hi All!

What if I want to aggregate data for periods between Monday and Sunday? Is there any straight forward way to do that? e.g. like setting up the first weekday as Monday in the system?


This discussion shows that Firefox is popular.
</description>
		<content:encoded><![CDATA[<p>Hi All!</p>
<p>What if I want to aggregate data for periods between Monday and Sunday? Is there any straight forward way to do that? e.g. like setting up the first weekday as Monday in the system?</p>
<p>This discussion shows that Firefox is popular.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Matt Wood</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6576</link>
		<pubDate>Tue, 16 Oct 2007 13:34:19 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6576</guid>
					<description>This works...

SELECT * FROM Table WHERE WEEK('Date',4) = 30;

It shows all the dates that are in the week number 30. I use mode 4 as Week 1 is the first week of the year, starting with a Sunday.</description>
		<content:encoded><![CDATA[<p>This works&#8230;</p>
<p>SELECT * FROM Table WHERE WEEK(&#8217;Date&#8217;,4) = 30;</p>
<p>It shows all the dates that are in the week number 30. I use mode 4 as Week 1 is the first week of the year, starting with a Sunday.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Luke Maciak</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6080</link>
		<pubDate>Thu, 06 Sep 2007 14:33:58 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6080</guid>
					<description>&lt;strong&gt;@Stuart&lt;/strong&gt; - Thanks Stuart! Good tip!</description>
		<content:encoded><![CDATA[<p><strong>@Stuart</strong> - Thanks Stuart! Good tip!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: shaun</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6077</link>
		<pubDate>Thu, 06 Sep 2007 12:28:08 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6077</guid>
					<description>select DATE_ADD('2007-09-07',INTERVAL(2-DAYOFWEEK('2007-09-07'))DAY);


swipe the date with what ever date you want to pass</description>
		<content:encoded><![CDATA[<p>select DATE_ADD(&#8217;2007-09-07&#8242;,INTERVAL(2-DAYOFWEEK(&#8217;2007-09-07&#8242;))DAY);</p>
<p>swipe the date with what ever date you want to pass
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Stuart</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6076</link>
		<pubDate>Thu, 06 Sep 2007 09:53:39 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-6076</guid>
					<description>I've been looking for an answer to this problem all morning and your solution worked great. I don't know if it has any performance benefits, but MySQL has a YEARWEEK() function which stops you having to group by WEEK() and YEAR().</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been looking for an answer to this problem all morning and your solution worked great. I don&#8217;t know if it has any performance benefits, but MySQL has a YEARWEEK() function which stops you having to group by WEEK() and YEAR().
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Luke Maciak</title>
		<link>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-5987</link>
		<pubDate>Thu, 30 Aug 2007 23:45:51 +0000</pubDate>
		<guid>http://www.terminally-incoherent.com/blog/2006/09/22/mysql-find-week-startend-based-on-week-number/#comment-5987</guid>
					<description>Hehe. Wow, my MySQL-Fu is still strong. :) Glad I could help.</description>
		<content:encoded><![CDATA[<p>Hehe. Wow, my MySQL-Fu is still strong. <img src="http://www.terminally-incoherent.com/blog/wp-includes/images/smilies/icon_smile.gif" alt=")" class="wp-smiley" />  Glad I could help.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.027 seconds -->
