Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show week start date

Status
Not open for further replies.

hessodreamy

Programmer
Feb 28, 2005
59
GB
I pull out a lot of reports for weekly figures, but is there any way to get the start date for a particulr week number?

 
for example:
Code:
SELECT from_unixtime(uts,'%u') as week_number, count(*) as orders from ordersTable WHERE from_unixtime(uts,'%Y')=2006
GROUP BY from_unixtime(uts,'%u')
Giving
+-------------+--------+
| week_number | orders |
+-------------+--------+
| 18 | 20 |
+-------------+--------+

weeks start on monday.
 
Code:
SELECT from_unixtime(uts,'%u') as week_number
     , [COLOR=blue]from_unixtime(uts - 
         mod(from_unixtime(uts,'%w')+6,7)
            *86400)  as start_of_week [/color]
     , count(*) as orders 
  from ordersTable 
 WHERE from_unixtime(uts,'%Y')=2006
GROUP 
    BY from_unixtime(uts,'%u')
     , [COLOR=blue]from_unixtime(uts - 
         mod(from_unixtime(uts,'%w')+6,7)
            *86400) [/color]

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top