3.15. Generating Time Ranges3.15.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.15.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:
3.15.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. The loop variable, $day is incremented a day at a time (86400 seconds) until it's no longer less than the epoch timestamp at the beginning of the next month:
3.15.4. See AlsoDocumentation on time( ) at http://www.php.net/time and strftime( ) at http://www.php.net/strftime.
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|