user3664402
user3664402

Reputation: 3

mysql print date as date(week no)

I have a mysql table with date column, I want to print my table in a pattern that in a same column it should print date as date(week no.) or date-week no.
e.g. 2014-06-05-Week 22 or 2014-06-05(Week 22).

Please suggest, my table looks like as below:

------------+-----------+-----------+------------+------------+------------+------------+------------+------------+  
 date       | 2006_2007 | 2007_2008 | 2008_2009  | 2009_2010  | 2010_2011  | 2011_2012  | 2012_2013  | 2013_2014  |  
------------+-----------+-----------+------------+------------+------------+------------+------------+------------+  
 2013-06-05 | 412684953 | 618821373 |  912382161 | 1152333713 | 1696469379 | 1992249499 | 2311645340 | 2525687604 |  

Upvotes: 0

Views: 130

Answers (1)

Anant Dabhi
Anant Dabhi

Reputation: 11104

use MySQL WEEK() returns the week number for a given date.

The argument allows the user to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53. If no argument is included with the function, it returns the default week format.

Syntax

WEEK(date[mode]);

Example

SELECT WEEK('2009-05-18',1);  

enter image description here

EDIT

SELECT CONCAT('2009-05-18', '-week ', WEEK('2009-05-18',1));    

Upvotes: 1

Related Questions