Php convert a date to string character [duplicate] - php

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I have searched but I could not find out how to convert a date from a character string. For example string date is 18-08-2016 I want to convert 18 August 2016 How can I do?

$input = '18-08-2016';
echo strftime('%d %B %Y',strtotime($input));// 18 August 2016
Use this resource to format the output to your liking.

Related

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

PHP display date as month name and date [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I am getting current date using the function date("Y-m-d").
I want to display date 2017-09-12 as sep 12
You can present it as ("M j"). Here is a test version.
this will do: date_format($date,"M/d");
Here is your date..
$myDate = "2017-09-12";
Then you have to convert your date with Date PHP function
$date = date("M d",mktime("0 0 0 ".$myDate));
echo $date will print Sep 12
d is Day of the month, 2 digits with leading zeros
M is a short textual representation of a month, three letters

How to change date format dmYhis to Y-m-d in PHP [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Convert this string to timestamp PHP [duplicate]
(2 answers)
Convert a date format in PHP [duplicate]
(18 answers)
Closed 5 years ago.
How to change date format dmYhis to Y-m-d in PHP. I have using the date() function but I cannot seem to make it work
$d = '24032017191551';
echo date('Y-m-d', strtotime($d));
Output: 1970-01-01
i want to get the ans is 2017-03-24
Below is the code to change date format
$retrieved ='24032017191551';
$date = DateTime::createFromFormat('dmYHis', $retrieved);
echo $date->format('Y-m-d');

Change date format with month name to dd/mm/YYYY [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 with a date in this format: April 16, 2017 23:59, I would like to write a function to change it so that it's in this format: dd/mm/YYYY eg 16/04/2017
I tried to use the date function but couldn't get it to work. Does anyone know how I can do this in PHP?
$date = 'April 16, 2017 23:59';
echo date("d/m/Y",strtotime($date));

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

Categories