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)
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)
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 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
This question already has answers here:
How to convert date to timestamp in PHP?
(22 answers)
Closed 9 years ago.
I have the following string: 2013-03-22
I need to convert that to a UNIX Timestamp.
How do I do this using PHP?
Use the strtotime function of PHP.
Like
$unixstamp = strtotime("2013-03-22");
With DateTime class
$dateTime = DateTime::createFromFormat('Y-m-d', '2013-03-22');
$dateTime->setTime(0, 0, 0);
echo $dateTime->getTimestamp();
Simple:
echo $time = strtotime("2013-03-22");
Using
strtotime("2013-03-22")
It will convert the date sting into timestamp value.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL]
Right now I have DATE stored in mysql as : YY-MM-DD. EX: 2011-12-22.
How can I convert using strtotime to MM-DD-YY in php?
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
or use the following link for the similar question
Convert date format yyyy-mm-dd => dd-mm-yyyy