How to reformat date in PHP?
date("F d, Y", strtotime($input))
PHP : reformat a date in
strtotime()
is able to handle the format that you have and convert it into timestamp. Then you can use it to format date in whatever format you want with date()
function:
$date_event = 'Fri, 30 Jun 2017 16:27:44 +0000 (UTC)';
echo date('d.m.Y H:i:s',strtotime($date_event));
//outputs: 30.06.2017 18:27:44
Here's working example:
https://3v4l.org/obfNB
Convert a date format in PHP
Use strtotime()
and date()
:
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
(See the strtotime and date documentation on the PHP site.)
Note that this was a quick solution to the original question. For more extensive conversions, you should really be using the DateTime
class to parse and format :-)
how to re-format datetime string in php?
why not use date() just like below,try this
$t = strtotime('20130409163705');
echo date('d/m/y H:i:s',$t);
and will be output
09/04/13 16:37:05
change the date format in laravel view page
Try this:
date('d-m-Y', strtotime($user->from_date));
It will convert date into d-m-Y
or whatever format you have given.
Note: This solution is a general solution that works for php and any of its frameworks. For a Laravel specific method, try the solution provided by Hamelraj.
PHP - Date Format to include a string
This should do the trick...
$date->format('l jS F Y \a\t g:ia');
You need to escape characters that are not intended to be used for date values.
Note that if you're using "
instead of '
for your format string you'll need to double escape n
, t
and r
characters as PHP will interpret them as newlines, tabs etc...
For example:
$date->format("l jS F Y \a\\t g:ia");
Converting Date format in PHP
Use strtotime() and date():
$originalDate = "Mon Apr 22 2013 12:16:00 GMT+0530 (India Standard Time)" ;
$newDate = date("Y-m-d H:i:s", strtotime($originalDate));
(see strtotime and date docs on the PHP site).
or use DateTime:
<?php
$source = "Mon Apr 22 2013 12:16:00 GMT+0530 (India Standard Time)";
$date = new DateTime($source);
echo $date->format("Y-m-d H:i:s"); // 22 2013 12:16:00
echo $date->format("Y-m-d H:i:s"); // 22 2013 12:16:00
?>
DEMO
Related Topics
Unexpected Character in Input: '\' (Ascii=92) State=1
Casting an Array with Numeric Keys as an Object
Install Imagick for PHP and Apache on Windows
Convert Ascii to Utf-8 Encoding
Sqlstate[Hy000] [1045] Access Denied for User 'Username'@'Localhost' Using Cakephp
Pre-Declare All Private/Local Variables
How to Use Cookies Across Two Different Domains
How to Load PHP File into Div by Jquery
Posting JSON Objects to Symfony 2
How to Type Hint More Than One Type
How to Run the PHP Code Asynchronous