Convert date format from 22/08/2015 20:36 [duplicate] - php

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
Good afternoon!
I have a simple question.
I have a date format in PHP
$ originalDate = "22/08/2015 20:36";
How to translate
2015-08-20 00:00:00
?

Try this:
<?php
$originalDate = "22/08/2015 20:36";
$date = DateTime::createFromFormat('d/m/Y H:i', $originalDate);
echo $date->format('Y-m-d H:i:s');
?>

Related

Convert Date yyyy-mm-dd to ddmmyy [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have the following date: 2010-04-19 . I would like to convert this date to the ddmmyy format.
Ref: http://php.net/manual/en/function.date.php
echo date('d/m/Y', strtotime( "2010-04-19" ));
Note:- you can go for different formats. like below:-
echo date('dmy', strtotime( "2010-04-19" ));
Example:- https://eval.in/802403 And https://eval.in/802404

Php converting date format not working [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
$date = "31/01/2017";
$date = date("Y-m-d", strtotime($date));
For some the above code is not working and giving me the result: $date = 1970-01-01;
When I am fetching date from database and converting in the same manner its working. But not working when i want to convert "d/m/Y" format to "Y-m-d"
I can convert the date in other ways by exploding, but why not the above code is working..??
try like this
<?php
$date = "31-01-2017";
$date = date("Y-m-d", strtotime($date));
echo $date;
?>
Output:
2017-01-31

Formatting date from dd-mm-yyyy to yyyy-mm-dd in php [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I have a string mm-dd-yyyy which i get from a form, which i want to store it in the database of the data-type DATE (yyyy-mm-dd).
How do i format the string and save it in the database ?
$new_format = date("Y-m-d", strtotime('04-28-2012'));
or
$date = new DateTime('04-28-2012');
$new_format = $date->format('Y-m-d');
or in PHP 5.5+
$new_format = (new DateTime('04-28-2012'))->format('Y-m-d');
Try
$date = DateTime::createFromFormat("m-d-Y", '02-15-2012');
echo $date->format('Y-m-d H:i:s') , "\n";
Output
2012-02-15 23:54:52

Formatting a date to a specific format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 9 years ago.
I have the following data available : 01/02/2014
What I need to format to is: 2014-01-02 00:00:00
What is the best way to do this in PHP?
$dt = DateTime::createFromFormat('m/d/Y', '01/02/2014');
echo $dt->format('Y-m-d 00:00:00');
See it in action
$val="01/02/2014";
echo date("Y-m-d H:i:s", strtotime($val));
Demo
First of all you should try it yourself.
you should study php date format documentation : http://www.php.net/manual/en/datetime.formats.date.php
Live demo:
https://eval.in/93149
$d = "01/02/2014";
echo date('Y-m-d H:i:s',strtotime($d));
OUTPUT:
2014-01-02 00:00:00
By using PHP date function
$date = "1st April 2000";
OR
$date = "01/04/2000";
echo date("Y-m-d H:i:s",strtotime($date));

Format string according to date format [duplicate]

This question already has answers here:
How do I convert an ISO8601 date to another format in PHP?
(2 answers)
Closed 8 years ago.
There is a string:
$time = "2013-07-10T21:00:00.000";
How to convert it to the format "2013-07-10 21:00:00"?
$time = strtotime("2013-07-10T21:00:00.000");
return strftime("%Y-%m-%d %H:%M:%S", $time);
$date = new \DateTime($time);
$date->format('Y-m-d H:i:s');
$time = "2013-07-10T21:00:00.000";
echo date("Y-i-d H:m:s",strtotime($time));

Categories