tailieunhanh - PHP and MySQL Web Development - P83

PHP and MySQL Web Development - P83: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | 382 Chapter 18 Managing the Date and Time You can pass in a 2- or 4-digit year to mktime .Two-digit values from 0 to 69 will be interpreted as the years 2000 to 2069 and values from 70 to 99 will be interpreted as 1970 to 1999. Using the getdate Function Another date-determining function you might find useful is the getdate function. This function has the following prototype array getdate int timestamp It takes a time stamp as parameter and returns an associative array representing the parts of that date and time as shown in Table . Table Associative Array Key-Value Pairs from getdate Function Key Value seconds Seconds numeric minutes Minutes numeric hours Hours numeric mday wday Day of the month numeric Day of the week numeric mon Month numeric year yday weekday month Year numeric Day of the year numeric Day of the week full text format Month full text format Validating Dates You can use the checkdate function to check whether a date is valid. This is especially useful for checking user input checkdate function has the following prototype int checkdate int month int day int year It will check whether the year is a valid integer between 0 and 32767 whether the month is an integer between 1 and 12 and whether the day given exists in that particu- lar month. The function takes leap years into consideration. For example checkdate 9 18 1972 will return true while checkdate 9 31 2000 will not. Converting Between PHP and MySQL Date Formats 383 Converting Between PHP and MySQL Date Formats Dates and times in MySQL are retrieved in a slightly different way than you might expect. Times work relatively normally but MySQL expects dates to be entered year first. For example the 29th of August 2000 could be entered as either 2000-08-29 or as 00-08-29. Dates retrieved from MySQL will also be in this order by default. To communicate between PHP and MySQL then we usually need to perform some date conversion. This can be done at either end. When putting dates .

TỪ KHÓA LIÊN QUAN