Specify my date PHP [duplicate] - 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

Related

Getting Month and Year from date [duplicate]

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

Hot to convert string into date in php [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 4 years ago.
I have a string
date = 25 aug 18
is there any way to convert this into date time format,
date = 25 August 2018
Use:
echo date('d F Y', strtotime("25 aug 2018")). "\n";
output: https://3v4l.org/2T9NF
refer:
http://php.net/manual/en/function.strtotime.php
http://php.net/manual/en/function.date.php

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

In php I have timestamp stored in session or cookie. How To Convert That Timestamp To Date & Time Format? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
Need Solution For Providing Date And Time.
Have a look to DateTime::createFromFormat:
$dt = DateTime::createFromFormat('d M Y h:i:s O', '01 Feb 2018 01:01:12 +0530');
echo $dt->format("Y-m-d H:i:s");
try this
$date = "Thu, 01 Feb 2018 01:01:12 +0530";
echo date("Y-m-d H:i:s",strtotime($date));

How to Convert Date String into Different format? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have a date that gets sent from a database which comes in a string format of '2018-01-01'. What I want to do is convert it into a string of month and year. E.G. 'January 2018'.
What would be the best way of doing so using PHP?
Try using the strtotime function to turn your string into a timestamp and the date function with the F Y format to get what you want:
$date = "2018-01-01";
$formatted = date("F Y", strtotime($date));

Categories