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?

3
  • 3
    week starting and ending can have different months.
    – ughai
    Commented Feb 11, 2016 at 8: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
    Commented Mar 12, 2016 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. Commented Mar 14, 2016 at 4:49

2 Answers 2

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.

0
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;
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.