This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
I have a difficulties regarding converting date into different format
The initial date format is 09/17/2014 which is, mm/dd/YYYY
I want to convert this into a new variable that shows Wednesday, September 17, 2014
How do i implement this?
thanks a bunch
Try with the following code using DateTime:
$dt = new DateTime('09/17/2014');
echo $dt->format('l, F d, Y');
Or use strtotime
echo date('l, F d, Y', strtotime("09/17/2014"));
Use strtotime.
echo date('l, F d, Y', strtotime("09/17/2014"));
Refer
http://in2.php.net/manual/en/function.strtotime.php
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 3 years ago.
I have a problem getting the year and month from the date given. I have this date 201911.. when i use
date('F Y',strtotime(201911))..
it shows Oct-19. It should be Nov-19
You would do better to use date_create_from_format:
$date = date_create_from_format('Ym', 201911);
echo $date->format('F Y');
Output:
November 2019
Demo on 3v4l.org
You are almost there. Just put ' around your String
echo date('F Y',strtotime('2019-11'));
Echo: November 2019
All of another responses are ok!. the problem is that you dont tell to php what is the format of the date that you need trasform.
DateTime::createFromFormat('Ym', 201911)->format('F Y');
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 6 years ago.
I have attribut date_input in my database
etat_input : 2016-06-06
I would convert my date on format:
since : 06 june 2016
I try with :
<?php echo $var['etat_input'];?>
but no result.
First convert date_input to timestamp:
$timestamp = strtotime($var['etat_input']);
Now feed that $timestamp to date with proper format:
date('d M Y', $timestamp);
PHP Sandbox example
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
php how to change date to this format [duplicate]
Closed 8 years ago.
I have this php script
date('dS F Y', strtotime($dateVariable))
The result is this:
01st September 2014
but I need the result as this: 01st Sep 2014
in other words, I need not the full name of the month. is that possible please?
date('dS M Y', strtotime($dateVariable))
Try as below
date('dS M Y', strtotime($dateVariable))
You can do it directly with the date function, using the 'M' mode.
http://php.net/manual/en/function.date.php
Alternatively, check out the function JDMonthName -- using mode 2 you can get the abbreviated month name.
http://php.net/manual/en/function.jdmonthname.php
Alternatively, check out the strftime function (much like printf) for formatting your date. The %b format gives the abbreviated month name.
http://php.net/manual/en/function.strftime.php
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 8 years ago.
database date format that i retrieve is
$event_date='2013-01-20';
and i want to convert this format to like this
Jan 1,2013
I have tried this
echo date('M d, Y',$event_date)
//but it is printing wrong value "Jan 01, 1970"
and giving error also: Notice (8): A non well formed numeric value encountered
if anyone can catch please help me to get correct value
You will need to use strtotime() function to correctly format the date since date() function expects second parameter to be a timestamp
echo date('M d, Y',strtotime($event_date));
From documentation
The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.
Live working sample here
date expects second parameter to be a timestamp http://php.net/date
http://php.net/strtotime is the way to go.
date('M d, Y', strtotime($event_date))
You should do:
echo date('M d, Y',strtotime($event_date));
try this....
echo date('M d, Y',strtotime($event_date));
Do like below
<?php $event_date='2013-01-20';
echo date('M d, Y', strtotime($event_date));
?>
Use DateTime to convert the Dateformat
<?php
$event_date='2013-01-20';
$date = new DateTime($event_date);
echo $date->format('M d, Y');
try this :
$event_date='2013-01-20';
echo date('M d, Y',strtotime($event_date));