2

I have a week number and a year (e.g. 34 and 2015). I want to get the name of the month to which the specified week belongs.

How can I do that?

Andriy M
  • 22,983
  • 6
  • 59
  • 103
  • 3
    week starting and ending can have different months. – ughai Feb 11 '16 at 08:30
  • 3
    What makes a week belong to a month? Starting day (if so Sunday or Monday)? Ending Day? Most of the days in the week are in month X? Please add some more detail to the question. I'm voting to close this question until it's clearer – Tom V Mar 12 '16 at 12:38
  • @TomV A week start with Monday (0) and end at Sunday (6). current week no 11 in current year. The week No 11 is belong to which month? I need Month name like March. – Sujeet Kumar Mar 14 '16 at 04:49

2 Answers2

0

Please try this:

SELECT MONTHNAME(STR_TO_DATE('201534  Monday','%X%V %W')) month_name

Instead of hardcoding the values, you can pass dynamic value also.

Paul White
  • 83,961
  • 28
  • 402
  • 634
Dipa
  • 80
  • 2
0

I solved my problem with this Perl logic:

my $time_piece_obj = Time::Piece->strptime('2016-01-01', '%Y-%m-%d');
my $ONE_WEEK = 604800;
my $wk_no=20;
$time_piece_obj += $wk_no*$ONE_WEEK;
my $month_name= $time_piece_obj->month;
print $month_name;
Paul White
  • 83,961
  • 28
  • 402
  • 634