If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > how to find the week number from the specified month.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-10, 23:46
sunny_007 sunny_007 is offline
Registered User
 
Join Date: Sep 2010
Posts: 141
Smile how to find the week number from the specified month.

Hi guys,
i have a doubt. I want to know how to get the week number of the month. For example, if the date is 6th of any month then value for week should be 1, if the date is 19th then value should be 3.



Thanks
Reply With Quote
  #2 (permalink)  
Old 11-19-10, 02:21
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
so either write a function in the front end
or consider using the modulo operator (%) on the DAY of the specified date

eg
Code:
SELECT my, column, list, (DAY(adatecolumn)+6)%7 AS weekno FROM mytable
you may need to tinker with the expression to make certain it meets your requirements

mind you to me its an odd definition of the week number, but its your app
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 12-07-10, 05:02
sid2986 sid2986 is offline
Registered User
 
Join Date: Oct 2010
Posts: 8
Make a calendar table and populate it with as many dates you want. To get data corresponding to the week number just do a left join from the table where you have data with its own date column.

the basic syntax would be :
select coalesce(CEILING(dayofmonth(calendar.datefield)/7),0)as WeekNumber from calendar;


Enjoy !
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On