Displaying strtotime() effectively in MySQL/PHP query

前端 未结 4 631
我寻月下人不归
我寻月下人不归 2021-01-23 11:09

This is my PHP/MySQL query, as mentioned at Displaying links in PHP/MySQL?:

http://pastebin.com/5Td9Bybn

I\'ll admit, I\'ve forgotten how to use the strtotime()

4条回答
  •  一整个雨季
    2021-01-23 11:49

    Option 1

    strtotime() will give you a timestamp, you use the function date() to format the display of time and/or date.

    06:00

    
    

    6:00am

    
    

    6am

    
    

    Read about date() and its formatting on php.net.


    Option 2

    Do it in MySQL, as @Marc B suggests.

    Change this line

    $result = mysql_query("SELECT * FROM presenters1;", $connection) or die("error querying database");
    

    to

    $result = mysql_query("SELECT *, TIME_FORMAT(airtime, '%h:%i') `airtime` FROM presenters1;", $connection) or die("error querying database");
    

    Then, change this line:

    to

提交回复
热议问题