knox203 Posted August 14, 2008 Share Posted August 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 14, 2008 Share Posted August 14, 2008 You could do this: echo "<!-- ".date('m-d-Y', strtotime(date('Y')."-01-00 +".($week-1)." weeks"))." -->"; Quote Link to comment Share on other sites More sharing options...
knox203 Posted August 14, 2008 Author Share Posted August 14, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.