|
Working with Date and Time
LAB: Capturing Date of Birth Using DateTime
What is the purpose of this lab?
- In this lab you will learn how to handle a birthdate.
- The date will be entered when a new member signs up.
- In the lab you will use DateTime to validate the date
- Using DateTime arithmetic you will detect if the new member is under age 21
Modify sweetscomplete/addmember.php ...
- From your editor open sweetscomplete/addmember.php
- Add a three fields:
- Day should be a drop down list from 1 to 31
- Month should be a drop down list with the months
- Year should be a drop down list from this year to this year - 120
- HINT: use a "for()" loop, arrays, and the "range()" function to produce the lists
Use DateTime to validate the date ...
- Build a DateTime object from the three fields
- Use try { xxx; } catch() { xxx } to capture any errors
- If an exception is thrown assume the information given was invalid
- Using date arithmetic generate an error if the birthdate indicates an age under 21
Test in the browser ...
- From your browser open http://localhost/sweetscomplete/addmember.php
- Try entering 2001-02-31
|
|