3.14.1. ProblemYou need to know all the days in a week or a month. For example, you want to print out a list of appointments for a week. 3.14.2. SolutionIdentify your start date using time( ) and strftime( ). If your interval has a fixed length, you can loop through that many days. If not, you need to test each subsequent day for membership in your desired range. For example, a week has seven days, so you can use a fixed loop to generate all the days in the current week, as in Example 3-39. Generating the days in a week
3.14.3. DiscussionA particular month or year could have a variable number of days, so you need to compute the end of the time range based on the specifics of that month or year. To loop through every day in a month, find the epoch timestamps for the first day of the month and the first day of the next month. In Example 3-40, the loop variable $day is incremented a day at a time (86,400 seconds) until it's no longer less than the epoch timestamp at the beginning of the next month. Generating the days in a month
3.14.4. See AlsoDocumentation on time( ) at http://www.php.net/time and strftime( ) at http://www.php.net/strftime . |