TAILIEUCHUNG - Giải pháp thiết kế web động với PHP - p 42

FORMATTING TEXT AND DATES Period Specifier %c Description Number without leading zero With leading zero Without leading zero With English text suffix Full text Abbreviated name, three letters 24-hour clock with leading zero 24-hour clock without leading zero 12-hour clock with leading zero 12-hour clock without leading zero Example 1, 9 01, 25 1, 25 1st, 25th Monday, Thursday Mon, Thu 01, 23 1, 23 01, 11 1, 11 Day of month %d %e %D Weekday name %W %a Hour %H %k %h %l (lowercase “L”) Minutes Seconds AM/PM %i %S %p With leading zero With leading zero 05, 25 08, 45 As explained earlier, when using a function in a SQL query, assign the. | FORMATTING TEXT AND DATES Period Specifier Description Example c Number without leading zero 1 9 Day of month d With leading zero 01 25 e Without leading zero 1 25 D With English text suffix 1st 25th Weekday name W Full text Monday Thursday a Abbreviated name three letters Mon Thu Hour H 24-hour clock with leading zero 01 23 k 24-hour clock without leading zero 1 23 h 12-hour clock with leading zero 01 11 l lowercase L 12-hour clock without leading zero 1 11 Minutes i With leading zero 05 25 Seconds S With leading zero 08 45 AM PM p As explained earlier when using a function in a SQL query assign the result to an alias using the AS keyword. Referring to Table 14-1 you can format the date in the created column of the blog table in a common . style and assign it to an alias like this DATE_FORMAT created c e Y AS date_created To format the same date in European style reverse the first two specifiers like this DATE_FORMAT created e c Y AS date_created If you use the original column name as the alias it converts the dates to strings which frequently plays havoc with the sort order. 391 CHAPTER 14 Download from Wow eBook PHP Solution 14-2 Formatting a MySQL date or timestamp This PHP solution formats the dates in the blog entry management page from Chapter 13. 1. Open or in the admin folder and locate the SQL query. It looks like this sql SELECT FROM blog ORDER BY created DESC Change it like this sql SELECT article_id title DATE_FORMAT created a b D Y AS date_created FROM blog ORDER BY created DESC I used single quotes around the whole SQL query so the format string inside DATE_FORMAT needs to be in double quotes. Make sure there is no gap before the opening parenthesis of DATE_FORMAT . The format string begins with a which displays the first three letters of the weekday name. If you use the original column name as the alias the ORDER BY clause sorts the dates in reverse alphabetical order Wed Thu Sun and so on.

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.