AndieB Posted May 24, 2007 Share Posted May 24, 2007 Hi all! I am creating a little own calendar. Now I want to add a "previous week" and "next week" functionality to the calendar. It is easy to take $thisWeek - 1; and $thisWeek + 1;, but there has to be a check wether it is the last week of the year and it should actually be a new year and head to week number 1. HOW do I make this kind of function? I use the following string names: $thisYear $thisWeek Thanks a lot for you help! Sincerely, Andreas Quote Link to comment https://forums.phpfreaks.com/topic/52797-check-week-number-in-end-of-year-and-begiining-of-new-year/ Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 if (($thisWeek - 1) < 1) { $thisWeek = 52; $thisYear = $thisYear - 1; } if (($thisWeek + 1) > 52) { $thisWeek = 1; $thisYear = $thisYear + 1; } Quote Link to comment https://forums.phpfreaks.com/topic/52797-check-week-number-in-end-of-year-and-begiining-of-new-year/#findComment-260670 Share on other sites More sharing options...
obsidian Posted May 24, 2007 Share Posted May 24, 2007 There isn't an easy solution to what you're after for this reason: weeks go from Sunday through Saturday, and the dates of the year very seldom overlap exactly with the week. So, if January 1 falls on Wednesday, you could accurately report it as either week 52 (for Sunday through Tuesday) or week 1 of the following year (for Wednesday through Saturday). Either way, simply grabbing weeks of the year is a little more difficult than simply checking what week of the year the current week is. Can you maybe define a few more rules for what you're after? If you can, I'm sure we can help you come up with a solution. Quote Link to comment https://forums.phpfreaks.com/topic/52797-check-week-number-in-end-of-year-and-begiining-of-new-year/#findComment-260675 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.