Getting Month and Year from date [duplicate] - php

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');

Related

how to get day, month and year from date function in php? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 3 years ago.
I am getting data in my php variable from database:
var_dump("The schedule is: ".$my_Schedule);
I am getting this output:
string(37) "Reviews created : 2019-10-19 03:47:57"
Now I want to use this data to show something like:
// My Desired Result
Oct 01, 2019
I don't want time here.
I am doing it like this:
<p><?=date('Y-m-d',$my_Schedule);?></p>
This is not working for me.
Kindly suggest what I am doing wrong.
Any idea or suggestion would be helpful.
Thank You.
Please use following code
echo date('M d,Y',strtotime('2019-10-19 03:47:57'));
You can use like this:
$date = date('M d, Y', strtotime('2019-10-19 03:47:57'));
echo $date;
// output Oct 19, 2019

How would I change one date format to another in PHP [duplicate]

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

Specify my date PHP [duplicate]

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

Converting Date with PHP [duplicate]

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

php date month from full name to short name [duplicate]

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

Categories