Reformation date in MYSQL for output in PHP

I have a ROW in my database table, which is the TYPE = timestamp. Thus, the format of the saved dates is as follows:

2015-11-30 14:54:04

I googled and said that this is the default timestamp format MYSQL. How can I repeat this date in PHP in this format:

November 30, 2015 2:54:04

Note. I run this in a loop, and the resulting data includes this date in the whole table, so for this era the value of the variable for this date $feeds->reg_date. Hope my question is clear.

+4
source share
3 answers

You can do something like this:

$dt = "2015-11-30 14:54:04";
$unixdatetime = strtotime($dt);
$formatted_date = strftime("%B %d, %Y %I:%M:%S %p",$unixdatetime);
echo $formatted_date;  // output: November 30, 2015 02:54:04 PM

Edited by:

$unixdatetime = strtotime($feeds->reg_date);
$formatted_date = strftime("%B %d, %Y %I:%M:%S %p",$unixdatetime);
echo $formatted_date;

edited by Re-

if(DateTime::createFromFormat('d/m/Y H:i:s', $feeds->reg_date)){
    $unixdatetime = DateTime::createFromFormat('d/m/Y H:i:s', $feeds->reg_date)->getTimestamp();
}else{
    $unixdatetime = strtotime($feeds->reg_date);
}
$formatted_date = strftime("%B %d, %Y %I:%M:%S %p",$unixdatetime);
echo $formatted_date;
+3
source

php, Date ('m-d-y')); , .

+1

date() strtotime()

$date = date('F d, Y h:i:s A', strtotime($row["date"]));

Check this link for a larger date format.

0
source

Source: https://habr.com/ru/post/1618047/


All Articles