Jump to content

Converting week number to first date of week


knox203

Recommended Posts

Hey everyone, I have some code that converts monday before last's date into the week of the year... I want to then convert it back later on to populate a drop down list. Here's the code:

 

<?php
$start_date = date('Y-m-d', strtotime("last monday -1 week")); // 08-04-2008
$week_num = date('W', strtotime($start_date)); // 32
?>

 

So far that works with no issues, it returns with week number 32 (08-04-08) which is correct since Monday is the first day of the week. Although, later on when I try to convert it back to a date with this code, I get "08-11-08" as the result (week #33):

 

<?php
echo "<!-- ".date('m-d-Y', strtotime(date('Y')."-01-00 +$week_num weeks"))." -->";
?>

 

Anyone have any ideas on what could be going wrong?

 

Thanks!

- Adam

Link to comment
Share on other sites

Hey Lemmin, thanks. That seems to work fine... although, do you think the issue is caused by the System (or PHP) interpreting the first day of the week as Sunday and not Monday? If so, do you know of any way to override that and set Monday as the first day?

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.