This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
How can I change the format of my date from 2016-10-05 to 10/05/2016 in php
$date= $row['date'];
So when the row echos out it'll all be the new format
Use DateTime to create an object (from the current format), allowing you to reformat the output.
$date = "2016-10-05";
$date = DateTime::createFromFormat('Y-d-m', $date);
echo $date->format('d/m/Y');
https://repl.it/DqvO
Related
This question already has answers here:
What is this date format? 2011-08-12T20:17:46.384Z
(11 answers)
Closed 3 years ago.
I'm using php and trying to determine what the following date/time format is so I can write PHP code to this date/time format
2019-12-17T17:23:49.782Z
This is iso 8061, so you can try like this:
$date = '2019-12-17T17:23:49.782Z';
$date = date('Y-m-d', strtotime(substr($date,0,10)));
echo $date;
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 4 years ago.
How would I change the date 18/08/2018 10:46:15 pm to Sat 25, 10:46:15 pm in PHP. I am doing the following:
```
$OldDate = "18/08/2018 10:46:15 pm";
$NewDate = $OldDate->format(D-j, Y-H:I:S);
echo $NewDate;
?>```
However, it is not showing anything, am I formatting it correctly?
Your old date is just a string. If you want to format it, you need to create a DateTime object using that string the constructor.
You're also incorrectly specifying the format
$OldDate = new DateTime("18/08/2018 10:46:15 pm");
echo $OldDate->format("L-j, h:i:s A");
http://php.net/manual/en/class.datetime.php
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have a date that gets sent from a database which comes in a string format of '2018-01-01'. What I want to do is convert it into a string of month and year. E.G. 'January 2018'.
What would be the best way of doing so using PHP?
Try using the strtotime function to turn your string into a timestamp and the date function with the F Y format to get what you want:
$date = "2018-01-01";
$formatted = date("F Y", strtotime($date));
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Convert this string to timestamp PHP [duplicate]
(2 answers)
Convert a date format in PHP [duplicate]
(18 answers)
Closed 5 years ago.
How to change date format dmYhis to Y-m-d in PHP. I have using the date() function but I cannot seem to make it work
$d = '24032017191551';
echo date('Y-m-d', strtotime($d));
Output: 1970-01-01
i want to get the ans is 2017-03-24
Below is the code to change date format
$retrieved ='24032017191551';
$date = DateTime::createFromFormat('dmYHis', $retrieved);
echo $date->format('Y-m-d');
This question already has answers here:
Convert from MySQL datetime to another format with PHP
(18 answers)
PHP mysql insert date format
(11 answers)
Closed 9 years ago.
I have a PHP function that gets passed a date in the format MM/DD/YYYY
I need to then convert this so that it can be added to a MySQL field that is of type date
How would I go about doing this in PHP?
$newvalue = date('Y-m-d', strtotime($originalvalue));
MySQL displays the DATE type as 'YYYY-MM-DD', so you could do something like:
date("Y-m-d",strtotime("10/18/2013"));
My variant:
$mysql_date = date('Y-m-d', strtotime(str_replace('/','-', $value)));
$date = preg_replace('/(\d{2})\/(\d{2})\/(\d{4})/', '$3-$1-$2', $date)