Jump to content

month name from week number


tkm

Recommended Posts

Hello Mates,

  I am using the following function to get the month name from week number of a year.

date( "M", strtotime( "+$wk_no week", mktime(0, 0, 0, 1, 1, 2008) ) )

 

But what happens when the week extends to 2 different months ? Can anyone help me with any insights or suggestions ? Thank you.

Link to comment
Share on other sites

That code gives you the first day of that week. You then add another 6 days to get the last day of the week, and then get the month name again. If they are different, you know the week spans two months.

 

Alternatively, you could see if the day of month + 6 is more than the number of days in the month. That way you can delay working out the month name a second time, in case you don't need to. But it's probably not a real performance issue, anyway.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.