PHP conversion date from MySQL query

I think this is a simple question. We have a MySQL database with a field DATE, the date is stored in US format (2010-06-01).

On my PHP page, where I will indicate the date, I just want to convert this date to the UK format (01-06-2010).

Any help and advice appreciated!

Thank,

Homer.

+3
source share
4 answers

, , , "--". strtotime unix, date , :

date("d-m-Y", strtotime($date_from_mysql));

date , . d , m , Y . , date, .

+13

mysql, DATE_FORMAT(). : "SELECT DATE_FORMAT(date_column,'%d-%m-%Y') my_formated_date;" , , , fetch my_formated_date

+3

You can analyze the date using this function:

http://php.net/manual/en/function.strtotime.php

It will return an integer, which is the number of seconds since 1970 (called the Unix timestamp).

Then use this function to format this number in any way:

http://ca3.php.net/manual/en/function.date.php

+1
source

You can also create a Date object in PHP using the DateTime :: createFromFormat function.

<?php
    $date = DateTime::createFromFormat('Y-m-d', $sql_date);
    echo $date->format('d-m-Y');
?>
+1
source

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


All Articles