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 Link to comment https://forums.phpfreaks.com/topic/119694-converting-week-number-to-first-date-of-week/ 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"))." -->"; Link to comment https://forums.phpfreaks.com/topic/119694-converting-week-number-to-first-date-of-week/#findComment-616733 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? Link to comment https://forums.phpfreaks.com/topic/119694-converting-week-number-to-first-date-of-week/#findComment-616954 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.