PHP: formatting a date from mySQL to be date only

前端 未结 3 777
情书的邮戳
情书的邮戳 2021-01-16 21:01

I am displaying some records from mySQL from php and one of the fields I echo out is a date field but it currently prints out the time at the end to.

How can I just

相关标签:
3条回答
  • 2021-01-16 21:36

    echo date('d-m-Y', strtotime($queryresult) );

    All date formatting options can be found here: http://nl3.php.net/manual/en/function.date.php

    0 讨论(0)
  • 2021-01-16 21:37

    The best way would be to do this on the DB level:

    SELECT CAST(yourfield AS DATE) FROM .....
    

    In PHP you can simply use this:

    $parts = explode(' ', $field);
    $datePart = $parts[0];
    
    0 讨论(0)
  • 2021-01-16 21:38

    The easiest way is to convert it in the mySQL query using DATE():

    SELECT columnname, DATE(datecolumn) FROM .....
    
    0 讨论(0)
提交回复
热议问题