Prev | Current Page 410 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


Lines 17??“21: If $Day is empty, output an empty cell. Otherwise, output the
day number.
Lines 23??“25: If $Day is the last day of the week, output a tag.
Pretty simple isn??™t it? Creating weekly and daily calendars operates on a very
similar premise. Just choose the appropriate class and adjust the format as you see fit.
Validating Dates and Times
While PHP??™s checkdate() function is useful for validating a date, it requires that all three
date components (month, day, and year) are provided. But what if you want to validate
CHAPTER 1 2 ?–  D ATE AND T IME 345
just one date component, the month, for instance? Or perhaps you??™d like to make sure a
time value (hours:minutes:seconds), or some particular part of it, is legitimate before
inserting it into a database. The Calendar package offers several methods for confirming
both dates and times, or any part thereof. This list introduces these methods:
isValid(): Executes all the other time and date validator methods, validating a
date and time
isValidDay(): Ensures that a day falls between 1 and 31
isValidHour(): Ensures that the value falls between 0 and 23
isValidMinute(): Ensures that the value falls between 0 and 59
isValidMonth(): Ensures that the value falls between 1 and 12
isValidSecond(): Ensures that the value falls between 0 and 59
isValidYear(): Ensures that the value falls between 1902 and 2037 on Unix, or
1970 and 2037 on Windows
Date and Time Enhancements for PHP 5.


Pages:
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422